【问题标题】:"Client was not authenticated to send anonymous mail during MAIL FROM"“在 MAIL FROM 期间,客户端未通过身份验证发送匿名邮件”
【发布时间】:2019-03-12 23:30:44
【问题描述】:

尝试使用 office 365 帐户通过 javamail 发送邮件时出现以下错误(替换了我的邮件地址和密码)

 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 jakarta-mail


    【解决方案1】:

    看起来您使用的是非常旧的 JavaMail 版本。尝试升级到current version

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

    【讨论】:

      猜你喜欢
      • 2018-08-02
      • 2019-10-21
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 2019-06-05
      • 2017-10-17
      相关资源
      最近更新 更多