我正在尝试使用Log4j2通过邮件发送错误日志。但是,我在连接到office365时遇到问题。
我的配置如下所示:
<SMTP name="Mail" subject="Worker Error" to="[email protected]" from="[email protected]"
smtpHost="smtp.office365.com" smtpPort="587" smtpUsername="[email protected]" 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:<[email protected]>
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?
有任何想法吗?
最佳答案
坚持使用smtp,并将其添加到您的初始化代码中:
import java.util.Properties;
...
Properties p = System.getProperties();
p.setProperty("mail.smtp.starttls.enable", "true");