Log4j2 SMTP发送邮件到Office365

3

我正在尝试使用Log4j2通过邮件发送我的错误日志,但是我连接到office365时遇到了问题。

我的配置如下:

<SMTP name="Mail" subject="Worker Error" to="recipient@domain.com" from="error@domain.com"
      smtpHost="smtp.office365.com" smtpPort="587" smtpUsername="error@domain.com" smtpPassword="mypassword"
      smtpProtocol="smtp" bufferSize="512" smtpDebug="true">
</SMTP>

这是我收到的错误信息。

EHLO 192.168.1.106
250-VI1PR02CA0004.outlook.office365.com Hello [80.110.25.16]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250 CHUNKING
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: use8bit false
MAIL FROM:<error@domain.com>
530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
DEBUG SMTP: got response code 530, with response: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

我尝试将协议更改为smtps,因为我认为它可能需要TLS,但它甚至无法连接。

DEBUG SMTP: trying to connect to host "smtp.office365.com", port 587, isSSL true
2015-10-20 10:51:24,625 main ERROR Error occurred while sending e-mail notification. javax.mail.MessagingException: Could not connect to SMTP host: smtp.office365.com, port: 587;
nested exception is:
     javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

有什么想法吗?
1个回答

1
坚持使用SMTP,并将以下代码添加到您的初始化代码中:
import java.util.Properties;
...    
Properties p = System.getProperties();
p.setProperty("mail.smtp.starttls.enable", "true");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接