关于smtp:使用gmail配置Jenkins电子邮件通知

Configuring Jenkins email notification with gmail

我尝试将jenkins配置为使用gmail作为POP提供程序发送电子邮件通知,但失败了

1
2
3
4
5
6
7
8
9
10
11
12
SMTP server - pop.gmail.com
Default user e-mail suffix - @gmail.com
Sender E-mail Address - Foobar CI <[email protected]>

Use SMTP Authentication - yes
User Name - your.email
Password - p******d

Use SSL - yes
SMTP Port - 995
Reply-To Address - [email protected]
Charset - UTF-8

测试失败:拒绝连接

javax.mail.MessagingException:无法连接到SMTP主机:pop.gmail.com,端口:995;
嵌套的异常是:
java.net.ConnectException:连接被拒绝:connect


Google SMTP服务器的主机名是smtp.gmail.com,如果您使用SSL,则正确的端口是465。

POP服务器通常仅用于接收邮件,而不用于发送邮件。


下面是更新的gmail SMTP服务器配置:

1
2
3
4
5
Gmail SMTP server address: smtp.gmail.com
Gmail SMTP user name: Your full Gmail address (e.g. [email protected])
Gmail SMTP password: Your Gmail password
Gmail SMTP port: 465
Gmail SMTP TLS/SSL required: yes

此配置对我来说很好。


由于谷歌增加了安全措施,因此上述配置不起作用。
从中触发邮件的Gmail帐户中需要其他配置。此步骤授权Jenkins之类的应用程序使用Gmail帐户。

https://support.google.com/accounts/answer/6010255

转到"我的帐户"中的"减少安全应用程序"部分。
在"访问不太安全的应用程序"旁边,选择打开。 (G Suite用户注意:如果您的管理员锁定了较不安全的应用程序帐户访问权限,此设置将被隐藏。)

此电子邮件成功触发后。


  • 获取应用程序专用密码

    • 登录到Gmail帐户>>导航到设置>>隐私和安全设置

    • 设置两步验证设置(因为没有两步验证,我们将无法生成应用专用密码)

    • 在Gmail帐户中设置两步验证设置后,导航回安全和隐私设置

    • 单击应用程序专用密码>>在下拉列表中以Jenkins的形式给出应用程序的名称(默认情况下,谷歌没有针对Jenkins的任何特定应用程序密码设置)>>这将生成密码,并记下生成的密码

  • 注意:由于密码对您的gmail帐户具有总体控制权,因此可能会导致严重后果

  • 设置用于发送gmail

    的SMTP配置

    • 登录后从仪表板

      导航至以下路径
      管理Jenkins >> configure system >> scroll down to email notification section

    • 输入以下参数

      1
      2
      smtp server : smtp.gmail.com
      default user email suffix : @gmail.com
    • 选择高级

    • 检查smtp身份验证

      1
      2
      username : (Your gmail id)
      password : (application specific password generated from previous step)
    • 检查使用SSL

      1
      2
      3
      SMTP port : 465
      Reply to address : [email protected](optional)
      Charset : UTF-8 (by default it is UTF-8)
    • 选择测试配置邮件

      1
      Test e-mail recipient : <enter recipient email id >

  • 单击测试配置,它将发送测试邮件到收件人电子邮件ID


    注意事项

    最新的mailer插件版本1.24有一个错误,即使您具有正确的配置,该错误也会导致测试配置失败(需要身份验证)。从官方网站下载1.23(.hpi文件)版本,然后从manage plugin-> advanced上传。重新启动Jenkins,它应该工作正常。

    仅需要启用安全性较低的应用访问权限,无需打开两步验证。


    以下屏幕截图说明了从GMail发送电子邮件所需的电子邮件配置。

    The


    我在Zapier的免费层上成功完成了此操作(无需打开gmail

    中的"安全性较低的应用")

  • 安装Jenkins通知插件。您可能需要重新启动Jenkins
  • 转到Zapier并创建Jenkins触发器
  • 在项目下的Jenkins中:配置->作业通知,填写选项。使用JSON似乎对我有用。
  • 在Zapier中添加Gmail操作。您应该可以通过gmail帐户中的单点登录进行设置。
  • PS。除了可以为我使用Zapier之外,我没有其他理由推荐Zapier,并且有一种解决方案可以不损害我的gmail帐户。


    以下设置对我来说很好用。

    Jenkis version: 2.204.1 Mailer Plug-in version: 1.30
    SMTP settings: SMTP Server - smtp.gmail.com Use
    SMTP Authentication - checked Username -
    [email protected] Password - your-gmail-password for
    the above account>

    注意:在您的google帐户设置中,必须禁用2要素身份验证,并且必须启用不安全应用程序访问权限

    Use SSL - checked SMTP port - 465 Charset - UTF-8 Test
    Connection - provide the recipient email address