Bonsoir,
voici un code simple qui me permet d'envoyé un mail, le probléme c'est qu'il m'affiche une exception :

L'envoi du mail a échoué : 530 5.7.0 Must issue a STARTTLS command first. 22sm1194753fkr.59

j'utilise : smtp.<FSI>

voici mon code
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
 
String from = "from@....com";
String to = "desitnatio@....com";
String subject = "le sujet...";
String content = "Le message en texte ou <b>html</b>";
 
 
 
try {
   Properties props = System.getProperties();
   props.put("mail.smtp.host", "smtp.gmail.com");
   Session ses = Session.getDefaultInstance(props, null);
   MimeMessage message = new MimeMessage(ses);
   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);
   javax.mail.Transport.send(message);
   System.err.println("Mail envoyé avec succée");
}
catch (Exception e) {
 System.err.println("L'envoi du mail a échoué : "+e.getMessage());
}