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)
原文地址:https://www.cnblogs.com/FlyAway2013/p/7504389.html