[Javamail] could not connect to smtp host
J'ai mis ce code dans une méthode
Code:
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
| Properties props = new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host", "smtp.mail.yahoo.fr");
props.put("mail.from", "mon_email@yahoo.fr");
props.put("mail.debug", "true");
props.put("mail.smtp.port", 465);
props.put("mail.smtp.socketFactory.port", 465);
props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getInstance(props,null);
try {
MimeMessage msg1 = new MimeMessage(session);
msg1.setFrom();
msg1.setRecipients(Message.RecipientType.TO,"toto@yahoo.fr");
msg1.setSubject("JavaMail hello world example");
msg1.setSentDate(new Date());
msg1.setText("Hello, world!\n");
Transport.send(msg1);
}
catch (MessagingException mex)
{
JOptionPane.showMessageDialog(null, mex);
} |
avec les import suivants:
Code:
1 2 3 4 5 6 7 8
| import java.util.Date;
import java.util.Properties;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;
import javax.activation.*;
import javax.mail.*; |
et lorsque je clic sur le bouton qui fait appel à cette méthode j'aurai l'exception suivante:
"could not connect to smtp host: smtp.mail.yahoo.fr, port 25; nested exception is java.net.socketException: Network is unreachable: connect"
est ce que je dois installer quelque chose ou...?
Aidez moi s'il vous plaît.
http://www.developpez.net/forums/d756100/java/general-java/apis/javamail-could-not-co
Essai un telnet pour te connecter sur le serveur de mail. Ca te permettra de savoir si le code est fautif.