Problème envoi de mail avec l'API JavaMail
Bonjour,
Tout d'abord je vous explique le but de mon programme, je souhaite créer une IHM qui permettrait aux personnes qui ont mon programme de me contacter par mail.
Pour l'interface graphique je me débrouille pas de problèmes.... Mais j'ai un soucis avec l'API JavaMail, j'ai deux ordinateurs à ma disposition mon pc portable et ma tour. Ils ont tout deux pour coder le logiciels Netbeans 7.3.1 (dernière version en date) avec la dernière (et même version) du JDK et du JRE. Bref j'ai télécharger chaque chose une seule fois et l'ai installer sur les deux. Je précise car j'ai lu sur un topic que mon problème pouvait venir de la version du JDK.
Bref j'en viens au problème, sur mon pc portable il fonctionne à merveille, je l'ai même envoyer à mon père qui la lui même testé et il fonctionne également.
Mais sur ma tour il ne fonctionne pas ! Et non plus sur le pc d'une amie...
L'ihm en elle même se présente avec 4 champs de textes (nom, email, tel, contenu du message) et un bouton d'envoi, qui fait appel à ma classe Send que voici :
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
package EnvoiMail;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;
public class Send {
private String nom;
private String email;
private String contenu;
private String tel;
private CarteVisiteFenetre CVFenetre;
protected String mailMoi = "contact@bibi.fr";
protected String host = "smtp.gmail.com";
protected String idgmail = "email_gmail_bibi@gmail.com";
protected String pwdgmail = "mdpbibi";
private Properties prop;
private Properties props;
public Send(CarteVisiteFenetre cvf,String name, String Mail, String Tel, String Cont){
this.CVFenetre = cvf;
this.nom = name;
this.email = Mail;
this.contenu = Cont;
this.tel = Tel;
this.prop = new Properties();
this.props = new Properties();
}
public void envoi () throws AddressException, MessagingException{
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.host", this.host);
prop.put("mail.smtp.port", "587");
prop.put("mail.smtp.starttls.enable", true);
Session sessionMail = Session.getInstance(prop,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(idgmail, pwdgmail);
}
});
MimeMessage msg = new MimeMessage(sessionMail);
sessionMail.setDebug(true);
try {
msg.setFrom(new InternetAddress(this.mailMoi));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(this.mailMoi));
msg.setSubject(this.nom);
msg.setText(this.contenu + "\n\nCe message a été envoyé par : " + this.email + "\nTel : " + this.tel);
Transport.send(msg);
JOptionPane.showMessageDialog(this.CVFenetre, "Votre email est envoyé.");
} catch (MessagingException ex) {
Logger.getLogger(Send.class.getName()).log(Level.SEVERE, null, ex);
//JOptionPane.showMessageDialog(this.CVFenetre, ex);
}
}
} |
Donc ce code fonctionne parfaitement sur mon pc portable, mais sur la tour il me renvoi cette erreurs :
Code:
1 2 3
| javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target |
De ce que je comprend il y a un problème de certificat, comment régler ce problème ? J'ai lu dans la doc JavaMail sur oracle qu'on pouvait régler le soucis avec un
Code:
prop.put("mail.protocol.ssl.trust", true);
Je l'utilise mal ? Car ça change rien...
Ca fait depuis ce matin que je rame si quelqu'un a une idée ?