Bonjour,
Je cherche à envoyé un mail en Java via JavaMail et voici mon erreur:
L'envoi du mail a échoué : Could not connect to SMTP host: localhost, port: 25
J'ai codé une méthode pour l'envoi du mail:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| /*Send mail*/
private void sendMail(String login, String password){
//****************
String from = "xxx@yahoo.fr";
String to = "yyy@hotmail.com";
String subject = "Test";
String content = "Message à envoyer"+login+" "+password;
String host = "localhost";
try{
Properties props = System.getProperties();
props.put("localhost", host);
javax.mail.Session ession=javax.mail.Session.getDefaultInstance(props,null);
MimeMessage message = new MimeMessage(ession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
//Envoi en HTML
message.setContent(content, "text/html");
//ou alors pour l'envoi en texte
message.setText(content);
Transport.send(message);
}catch (Exception e){
System.err.println("L'envoi du mail a échoué : "+e.getMessage());
}
} |
et j'ai ajouté un bout de code dans le context.xml:
1 2 3 4 5 6
|
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/HorensII">
<Resource name="mail/Session" auth="Container" type="javax.mail.Session" mail.smtp.host="localhost"/>
</Context> |
Que faut-il faire pour qu'il puisse reconnaitre le serveur smtp comme étant en local?
Merci pour votre aide.
Partager