Bonjour à tous,

Je suis en train d'effectuer un essai d'envoi de mail grâce à ce code ci-dessous :

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
 
 
package sendemail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
 
public class SendMail {
    public static void main(String[] args) {
      String to = "contact@destinataire.com";
      String from = "contact@domaine.com";
      String host = "mail.domaine.com";
 
      Properties properties = System.getProperties();
      properties.put("mail.smtp.host", host);
      properties.put("mail.smtp.port", "587");
      properties.put("mail.smtp.ssl", true);
	  properties.put("mail.smtp.starttls", true);
      properties.put("mail.smtp.auth", true);
 
      Session session = Session.getInstance(properties, new javax.mail.Authenticator(){
        protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication("contact@domaine.com", "*******");
        }
      });
 
      try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setSubject("This is the email subject");
        message.setText("This is the email body");
 
        Transport.send(message);
      } catch (MessagingException mex) {
        mex.printStackTrace();
      }
   }
}
Cependant j'ai un échec d'envoi de mail avec avec un message d'erreur suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
 
java -classpath lib\mail.jar;lib\activation.jar;sendemail\classes sendemail.SendMail
javax.mail.SendFailedException: Sending failed;
  nested exception is:
        class javax.mail.MessagingException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
 
        at javax.mail.Transport.send0(Transport.java:218)
        at javax.mail.Transport.send(Transport.java:80)
        at sendemail.SendMail.main(SendMail.java:37)

Pourtant je renseigne le bon mot de passe.

Est-ce que quelqu'un pourrait m'éclairer la raison de cet échec, s'il vous plaît ?

Cordialement.