Erreur "javax mail AuthenticationFailedException"
Bonjour ,
j'ai essayé pas mal de code pour envoyer un mail via Javamail
je me suis fixer sur le code suivant
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
| package aaa;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class smtpTest {
public static void main (String[] args) throws Exception {
String smtpHost = "smtp.gmail.com";
String from = "zzzzzz@gmail.com";
String to = "zzzzzz@gmail.com";
String username = "zzzzzzz";
String password = "xxxxx";
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello");
message.setText("Hello World");
Transport tr = session.getTransport("smtp");
tr.connect(smtpHost, username, password);
message.saveChanges();
// tr.send(message);
/** Genere l'erreur. Avec l authentification, oblige d utiliser sendMessage meme pour une seule adresse... */
tr.sendMessage(message,message.getAllRecipients());
tr.close();
}
} |
lors de l’exécution ça marche po :cry: et ça donne l'erreur suivante ::
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
| 220 mx.google.com ESMTP o47sm1505042eem.0
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
EHLO SIHAM-PC
250-mx.google.com at your service, [105.129.59.81]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250-ENHANCEDSTATUSCODES
250 STARTTLS
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
Exception in thread "main" javax.mail.AuthenticationFailedException: 535-5.7.1 Application-specific password required. Learn more at
535 5.7.1 http://support.google.com/accounts/bin/answer.py?answer=185833 o47sm1505042eem.0
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at aaa.smtpTest.main(smtpTest.java:34) |
:calim2: est ce que vous pouvez m'aider??