Bonjour,
je tente d'implémenter une routine d'envoi de mail par Google tel que expliqué à ce lien: http://www.mkyong.com/java/javamail-...-smtp-example/.
Mais ça ne marche pas. J'ai des messages d'exceptions comme ci-dessous:
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
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
at com.scse.test.SendMailSSL.main(SendMailSSL.java:50)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
J'arrive à "pinguer" le serveur: >ping smtp.gmail.com
Quelqu'un peut-il m'aider à envoyer les mails en Java à partir du serveur smtp.gmail.com ?
Je vous donne ci-dessous le code :
Je vous remercie par avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class SendMailSSL { /** * @param args */ public static void main(String[] args) { Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("tartapion","tartapion"); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("("tartapion@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("("tartapion@gmail.com")); message.setSubject("Testing Subject"); message.setText("Dear Mail Crawler," + "\n\n No spam to my email, please!"); System.out.println("session=" + session); //Transport.send(msg, addresses) Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { throw new RuntimeException(e); } } }
Bobi
Partager