简体   繁体   English

使用 jenkins 发送电子邮件时出错

[英]Error when sending email with jenkins

I'm trying to use email sending in jenkins.我正在尝试在詹金斯中使用电子邮件发送。 I leave default values, click on 'Test configuration' button and get error:我保留默认值,单击“测试配置”按钮并出现错误:

Failed to send out e-mail发送电子邮件失败

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; javax.mail.MessagingException:无法连接到 SMTP 主机:本地主机,端口:25; nested exception is: java.net.SocketException: Permission denied: connect嵌套异常是:java.net.SocketException:权限被拒绝:连接

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)在 com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)在 com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)

What I missed?我错过了什么? It's not working by default?默认情况下它不起作用?

I configured Jenkins with my gmail account using the settings as given in the image below.我使用下图中给出的设置使用我的 gmail 帐户配置了 Jenkins。

在此处输入图像描述

I had similar problem couldn't send email via zoho.我有类似的问题无法通过 zoho 发送电子邮件。 The configurations were: SMPT TLS Zoho Configurations I just need to change system admin address in jenkins configurations to the same one in email-notifications.配置是: SMPT TLS Zoho 配置我只需要将 jenkins 配置中的系统管理员地址更改为电子邮件通知中的相同地址。

Here you can find the system admin e-mail: Manage Jenkins -> Configure System -> Jenkins Location -> System Admin e-mail address在这里您可以找到系统管理员电子邮件:Manage Jenkins -> Configure System -> Jenkins Location -> System Admin e-mail address

I was also struggling with this error.我也在为这个错误而苦苦挣扎。 Here is how I resolved it.这是我解决它的方法。

1. Google account settings: 1.谷歌账户设置:

Go to Gmail account settings -> Forwarding and POP/IMAP -> IMAP Access -> Enable IMAP (This is to enable both IMAP & SMTP settings)转到 Gmail 帐户设置 -> 转发和 POP/IMAP -> IMAP 访问 -> 启用 IMAP(这是启用 IMAP 和 SMTP 设置)

Check configuration details that are mentioned as:检查提到的配置详细信息

  • Outgoing Mail (SMTP) Server: smtp.gmail.com外发邮件 (SMTP) 服务器:smtp.gmail.com
  • Requires SSL: Yes需要 SSL:是
  • Requires TLS: Yes (if available)需要 TLS:是(如果可用)
  • Requires Authentication: Yes需要身份验证:是
  • Port for SSL: 465 SSL 端口:465
  • Port for TLS/STARTTLS: 587 TLS/STARTTLS 端口:587

(Rather than going with settings mentioned by anyone, please checkout your account for this info as settings/configurations keep on changing. ) (不要使用任何人提到的设置,请检查您的帐户以获取此信息,因为设置/配置不断变化。)

2. Jenkins (2.121.3) settings: 2.詹金斯(2.121.3)设置:

Manage Jenkins -> Configure System -> Scroll down to E-mail Notification tab -> Advanced管理 Jenkins -> 配置系统 -> 向下滚动到电子邮件通知选项卡 -> 高级

  • Use SMTP Authentication: checked使用 SMTP 身份验证:选中
  • User Name: <your gmail id>用户名:<你的 gmail id>
  • Password: <your password>密码:<您的密码>
  • Use SSL: checked使用 SSL:勾选
  • SMTP Port: 465 SMTP端口:465
  • Reply-To Address: Optional (I left it blank. You can give any email id you want)回复地址:可选(我将其留空。您可以提供任何您想要的电子邮件 ID)
  • Charset: UTF-8字符集:UTF-8

Enable "Test configuration by sending test e-mail", give test email id and hit "test configuration" button启用“通过发送测试电子邮件测试配置”,提供测试电子邮件 ID 并点击“测试配置”按钮

NOTE:笔记:

  1. Make sure you are connected to open network (that is not antivirus protected or antivirus may block your emails).确保您已连接到开放网络(不受防病毒保护或防病毒可能会阻止您的电子邮件)。 I used my phone internet instead of office internet for testing this.我使用我的手机互联网而不是办公室互联网来测试这个。
  2. I didn't change any McAfee settings for doing this.为此,我没有更改任何 McAfee 设置。 Just switch your internet to open one.只需切换您的互联网以打开一个。

There is no SMTP server running on localhost or you don't have the permission to connect to it.本地主机上没有运行 SMTP 服务器,或者您没有连接到它的权限。

Check the configuration of Jenkins.检查 Jenkins 的配置。

If anyone is still having issues with emails in Jenkins, a lot has changed since then.如果有人仍然对 Jenkins 中的电子邮件有问题,那么从那时起已经发生了很多变化。

If you have a custom domain name for g-mail and it requires a 2-step authentication to login, for example you@yourcompany.com ,如果您有 g-mail 的自定义域名并且需要两步验证才能登录,例如you@yourcompany.com

SMTP server should still be smtp.gmail.com SMTP 服务器仍应为smtp.gmail.com

Default user e-mail suffix should be @yourcompany.com默认用户电子邮件后缀应为@yourcompany.com

Because Google no longer allows you to simply use your default e-mail password to login via any outside apps, in this case Jenkins.因为谷歌不再允许您简单地使用您的默认电子邮件密码通过任何外部应用程序登录,在本例中为 Jenkins。 It is a lot more secure to let Google create a custom password for Jenkins rather than turning off G-Mail's security features to allow Jenkins access to your account.让 Google 为 Jenkins 创建自定义密码比关闭 G-Mail 的安全功能以允许 Jenkins 访问您的帐户要安全得多。

Create the App Password here: https://security.google.com/settings/security/apppasswords在此处创建应用密码https ://security.google.com/settings/security/apppasswords

Use the generated password in Jenkins -> Configure Systems -> E-Mail ConfigurationJenkins -> Configure Systems -> E-Mail Configuration中使用生成的密码

You probably don't have SMTP running on your machine, which is the usual state for Windows or Mac servers.您的机器上可能没有运行 SMTP,这是 Windows 或 Mac 服务器的通常状态。

To test this , use any known mail-server for that, for example - if you have a gmail account, try this:要对此进行测试,请使用任何已知的邮件服务器,例如 - 如果您有 gmail 帐户,请尝试以下操作:

SMTP server: smtp.gmail.com SMTP 服务器: smtp.gmail.com

Default user e-mail suffix: @something.something默认用户电子邮件后缀: @something.something

Sender E-mail Address: your-mail@gmail.com发件人电子邮件地址: your-mail@gmail.com

If planning to use the mail-notifications as part of your build-process,如果计划将邮件通知用作构建过程的一部分,
it is best to set the SMTP properly, or maybe move the Jenkins/Hudson server to a machine that supports this.最好正确设置 SMTP,或者将 Jenkins/Hudson 服务器移动到支持它的机器上。

Check if your provider blocks port 25.检查您的提供商是否阻止端口 25。

In order to make a proper test为了进行适当的测试

telnet smtp.gmail.com 25远程登录 smtp.gmail.com 25

If you receive an answer like this:如果你收到这样的回答:

telnet: connect to address 74.125.206.108: Connection refused telnet:连接到地址 74.125.206.108:连接被拒绝

You should go with smtp authentication as described in harikrishna-pai's answer您应该按照harikrishna-pai 的回答中所述使用 smtp 身份验证

I had same issue and managed to resolved by following,我有同样的问题,并设法通过以下方式解决,

  1. Generate Gmail App Password, Gmail App生成 Gmail 应用密码, Gmail 应用

  2. In Jenkins use the app password, Jenkin's Configuration在Jenkins中使用app密码, Jenkin的Configuration

I Had the same issue.我遇到过同样的问题。 After witch hunting a lot, I found a solution as below:经过大量的女巫狩猎之后,我找到了如下解决方案:

even turn on - less secure apps, I was struggling since 6 hour.甚至打开 - 安全性较低的应用程序,我从 6 小时开始就在苦苦挣扎。 the second option: And go to https://accounts.google.com/DisplayUnlockCaptcha第二个选项:然后转到https://accounts.google.com/DisplayUnlockCaptcha

and click Continue.然后单击继续。

this resolved the issue.这解决了这个问题。

I had the same issue as i was using avast it blocked smtp mails so i disabled it and it worked我在使用 avast 时遇到了同样的问题,它阻止了 smtp 邮件,所以我禁用了它并且它有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM