Salut,
J'excecute ce code pour essayer d'envoyer un mail
@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
28
29
30
31
   String to = "receiver";
  String from = "sender";
  String host = "host";
  Properties props = new Properties();
  props.put("mail.smtp.host", host);
  props.put("mail.debug", "true");
  props.put("mail.smtp.auth", "true");
  Session session = Session.getDefaultInstance(props, null);
// Session session = Session.getDefaultInstance(props); 
       try {
                Message msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress(from));
                InternetAddress[] address = {new InternetAddress(to)};
                msg.setRecipients(Message.RecipientType.TO, address);
                msg.setSubject("Test E-Mail through Java");
                msg.setSentDate(new Date());
 
                // Set message content
                msg.setText("This is a test of sending a " +
                            "plain text e-mail through Java.\n" +
                            "Here is line 2.");
                Transport tr = session.getTransport("smtp");
                tr.connect(host,"userName" , "PassWd");
                //Send the message
                tr.send(msg);
            }
            catch (MessagingException mex) {
                // Prints all nested (chained) exceptions as well
                mex.printStackTrace();
            }
        }
J'ai egalement essayer Authenticator pour creer la session donc au lieu d'utiliser Session.getDefaultInstance(props, null); je fais Session.getDefaultInstance(props, auth); auth de type Authenticator.
Toujours avec tout ça je reçois l'exception suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
com.sun.mail.smtp.SMTPSendFailedException: 530 <sender>... MAIL requires AUTH
 
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at sendingMails.main(sendingMails.java:54)
De l'aide.