“客户端未通过身份验证,无法在MAIL FROM期间发送匿名邮件”

问题描述 投票:0回答:1

尝试使用Office 365帐户发送带有javamail的邮件收到以下错误(替换了我的邮件地址和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);
smtp office365 javamail
1个回答
0
投票

看起来你正在使用一个非常旧版本的JavaMail。尝试升级到current version

此外,您可以通过getting rid of the Authenticator简化代码。

© www.soinside.com 2019 - 2024. All rights reserved.