Jenkins 之郵件配置


 

 Jenkins 之郵件配置其實還是有些麻煩的,坑比較多,一不小心就。。。我是走了很多彎路的。

這里記錄下來,希望大家以后不要重蹈覆轍:

 

 

我測試過,這里的 Extended E-mail Notification 好像沒什么用, 隨便寫都不會報錯,也不影響結果。 不知道干嘛的。

 

 

 

選中上面的“通過發送測試郵件測試配置”:

 

 填寫相關信息, 注意, 用戶密碼是發送方郵件地址的用戶密碼, 用戶名必須和 系統管理員郵件地址一致。

 用戶默認郵件后綴, 寫錯了好像也不影響結果。 我猜 它的作用是, 發郵件時候, 郵件接收方 如果沒有 @qq.com ,@sina.com 這樣的后綴, 那么就會補上這個。 它是這個作用。不過,試了下,發現不行, sina 的stmp:

com.sun.mail.smtp.SMTPAddressFailedException: 501 Syntax error
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:
1686) Caused: javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 501 Syntax error at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098) at javax.mail.Transport.send0(Transport.java:195)

或者163 的stmp 出現:

com.sun.mail.smtp.SMTPAddressFailedException: 550 Invalid User: robert


    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1686)

Caused: javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 Invalid User: robert


    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835)

    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)

    at javax.mail.Transport.send0(Transport.java:195)

 

SSL 是可以選的。我試過 sina, 163 郵箱, 選擇或不選 SSL , 發送郵件都是沒問題的。 但是對於,qq 郵箱,SSL 是必須選的, 否則:

Failed to send out e-mail

javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28
    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:809)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:752)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)

另外,默認情況下,QQ郵箱 的STMP 功能是關閉的,如有需要手動啟動。 開啟的時候需要發送短信驗證,比較麻煩。參考: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=166 

 

STMP服務器是不能寫錯的,需要和發送方郵件地址對應上,否則:

Failed to send out e-mail
java.net.UnknownHostException: smtp.siaana.com  // 這里故意寫錯成了
smtp.siaana
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589)

 

 

一般郵件發送方是需要認證的,這里我們選擇用戶密碼方式,用戶密碼一定要正確,否則出現錯誤:

javax.mail.AuthenticationFailedException: 535 5.7.8 authentication failed
    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:809)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:752)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)

 用戶不存在也是這個錯誤。總之 535 5.7.8 authentication failed 是認證錯誤

 

另外, 

  Jenkins Location -> 系統管理員郵件地址 需要和 郵件通知-> 用戶名 這里的配置一致, 否則出現:

Failed to send out e-mail

com.sun.mail.smtp.SMTPSenderFailedException: 553 Envolope sender mismatch with login user..
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1587)
Caused: com.sun.mail.smtp.SMTPSendFailedException: 553 Envolope sender mismatch with login user..
;
  nested exception is:
    com.sun.mail.smtp.SMTPSenderFailedException: 553 Envolope sender mismatch with login user..
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2057)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1580)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM