2015-10-20 75 views
2

我想通過郵件使用Log4j2發送我的錯誤日誌。不過,我有問題連接到office365。Log4j2 SMTP到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? 

任何想法?

回答

0

棒與SMTP,並添加到您的初始化代碼:

import java.util.Properties; 
...  
Properties p = System.getProperties(); 
p.setProperty("mail.smtp.starttls.enable", "true");