saviarim
Messages postés2Date d'inscriptiondimanche 10 mai 2015StatutMembreDernière intervention13 mai 2015
-
Modifié par KX le 13/05/2015 à 21:48
Bonjour,
j'ai une servlet qui envoi des message mail j'utilise mail.jar et gmail yahou ..ect comme serveur .
le servlet ne signale pas erreur mais l'envoi du msg na pas marcher je ne sais pas pourquoi ,j'ai besoin de votre aide merci d'avance
voici mon code :
package Controleur;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/SendemailServlet")
public class SendemailServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String to = "wehbeahmedou@gmail.com";
String from = "necibe460@gmail.com";
String host = "smtp.planet.tn";
//String host = "196.203.35.80";
//String filename = "c:\\sig.sig";
boolean debug = false;
String msgText1 = "Sending a file.\n";
String subject = "Sending a file";
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getInstance(props, null);
session.setDebug(debug);
try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
String content =null;
mbp1.setText(content);
// create the second message part
//MimeBodyPart mbp2 = new MimeBodyPart();
//attach the file to the message
//FileDataSource fds = new FileDataSource(filename);
//mbp2.setDataHandler(new DataHandler(fds));
//mbp2.setFileName(fds.getName());
// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
//mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header
msg.setSentDate(new Date());
// send the message
Transport.send(msg);
} catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
}