«Клиент не прошел аутентификацию для отправки анонимной почты во время ПОЧТЫ ОТ» - PullRequest
0 голосов
/ 12 марта 2019

При попытке отправить почту с помощью javamail с использованием учетной записи office 365 появляется следующая ошибка (заменил мой почтовый адрес и P / w)

 Host : smtp.office365.com,
 Port : 587
User : myMailAddress@MyDomain, 
 Pw :MyPassword
From : myMailAddress@MyDomain, To : AnotherMailAddress@MyDomain
Subject : Auto Reply:testing Log
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true

DEBUG: SMTPTransport trying to connect to host "smtp.office365.com", port 587

DEBUG SMTP RCVD: 220 LO2P123CA0023.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 12 Mar 2019 11:47:00 +0000

DEBUG: SMTPTransport connected to host "smtp.office365.com", port: 587

DEBUG SMTP SENT: EHLO LP-058
DEBUG SMTP RCVD: 250-LO2P123CA0023.outlook.office365.com Hello [1.22.231.94]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8

DEBUG SMTP Found extension "SIZE", arg "157286400"
DEBUG SMTP Found extension "PIPELINING", arg ""
DEBUG SMTP Found extension "DSN", arg ""
DEBUG SMTP Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP Found extension "STARTTLS", arg ""
DEBUG SMTP Found extension "8BITMIME", arg ""
DEBUG SMTP Found extension "BINARYMIME", arg ""
DEBUG SMTP Found extension "CHUNKING", arg ""
DEBUG SMTP Found extension "SMTPUTF8", arg ""
DEBUG SMTP: use8bit false
DEBUG SMTP SENT: MAIL FROM:<mailaddress@mydomain>
DEBUG SMTP RCVD: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [LO2P123CA0023.GBRP123.PROD.OUTLOOK.COM]
DEBUG SMTP SENT: QUIT

У меня есть данные электронной почты, которые хранятся в файле свойств следующим образом:

mail.smtp=smtp.office365.com
mail.user=myMailAddress@MyDomain
mail.pwd=MyPassword
mail.port=587 

мой код выглядит следующим образом:

mailProperties = new Properties();
mailProperties.load(new FileInputStream(System.getProperty("user.dir")+"/bizsol/bizproperties/mail.properties"));
props = new Properties();
props.setProperty("mail.host", ""+mailProperties.get("mail.smtp")); 
props.put("mail.smtp.auth", "true");    
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.port",""+mailProperties.get("mail.port")); 

final PasswordAuthentication pauth;

String x=mailProperties.get("mail.user").toString();
String y=mailProperties.get("mail.pwd").toString();

pauth = new javax.mail.PasswordAuthentication(x,y);

mail = Session.getInstance(props, new Authenticator() {
  protected PasswordAuthentication getPasswordAuthentication() { return pauth; }                            
});

mail.setDebug(true);
msg = new MimeMessage(mail);
multi = new MimeMultipart();
BodyPart part1 = new MimeBodyPart();
part1.setText(matter);
multi.addBodyPart(part1);

msg.setFrom(fromAdd);
msg.setRecipients(Message.RecipientType.TO,getAddresses(to));
msg.setSubject(subject);
Transport.send(msg);

1 Ответ

0 голосов
/ 12 марта 2019

Похоже, вы используете очень старую версию JavaMail.Попробуйте обновить до текущей версии .

Кроме того, вы можете упростить свой код, избавившись от Authenticator .

...