gitlab-设置邮件SMTP以及GitLab收不到邮件的问题

简介: gitlab-设置邮件SMTP以及GitLab收不到邮件的问题

1. 配置邮箱

sudo vi /etc/gitlab/gitlab.rb

这里我使用的qq邮箱,在邮箱设置里打开POP3/SMTP服务,并保存好16位授权码。

gitlab_rails['smtp_enable'] = true

gitlab_rails['smtp_address'] = "smtp.qq.com"

gitlab_rails['smtp_port'] = 465

gitlab_rails['smtp_user_name'] = "******@qq.com"

gitlab_rails['smtp_password'] = "授权码"

gitlab_rails['smtp_domain'] = "smtp.qq.com"

gitlab_rails['smtp_authentication'] = "login"

gitlab_rails['smtp_enable_starttls_auto'] = true

gitlab_rails['smtp_tls'] = true

gitlab_rails['gitlab_email_from'] = '******@qq.com'

修改上面的邮箱地址和验证码,其它的不要动。

保存好后重启 gitlab-ctl reconfigure

2. 测试配置是否成功:

执行 gitlab-rails console进入控制台。

发送一封测试邮件:Notify.test_email('收件人邮箱', 'title', 'body').deliver_now

结果如下:

Notify#test_email: processed outbound mail in 0.8ms

Sent mail to xxxx@qq.com (1.7ms)

Date: Wed, 29 May 2019 12:42:16 +0800

From: GitLab

Reply-To: GitLab

To: xxxx@qq.com

Message-ID: <5cee0da88e622_1f4e3fcaf82d65ec6262@localhost.localdomain.mail>

Subject: title

Mime-Version: 1.0

Content-Type: text/html;

charset=UTF-8

Content-Transfer-Encoding: 7bit

Auto-Submitted: auto-generated

X-Auto-Response-Suppress: All

body

Traceback (most recent call last):

      1: from (irb):3

SocketError (getaddrinfo: Name or service not known)

前面都正常,最后报了错。看起来前面的配置是没有问题的。

多方查找,是DNS的问题,自动获取DNS改为手动配置,填8.8.8.8。

继续测试发送邮件成功,问题解决。

3.测试邮件提示

-----------------------------------------------------------------

root@test204:[/root] gitlab-rails console

-------------------------------------------------------------------------------------

GitLab:      11.8.1 (657d508)

GitLab Shell: 8.4.4

postgresql:  9.6.11

-------------------------------------------------------------------------------------

Loading production environment (Rails 5.0.7.1)

irb(main):001:0> Notify.test_email('15201086747@sina.cn', 'title', 'body').deliver_now

Notify#test_email: processed outbound mail in 566.8ms

Sent mail to 15201086747@sina.cn (5412.3ms)

Date: Wed, 01 Apr 2020 15:30:11 +0800

From: GitLab

Reply-To: GitLab

To: 15201086747@sina.cn

Message-ID: <5e844303f3081_30a13fe04bade60048952@test204.mail>

Subject: title

Mime-Version: 1.0

Content-Type: text/html;

charset=UTF-8

Content-Transfer-Encoding: 7bit

Auto-Submitted: auto-generated

X-Auto-Response-Suppress: All

body

Traceback (most recent call last):

     16: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/actionmailer-5.0.7.1/lib/action_mailer/message_delivery.rb:96:in `block in deliver_now'

     15: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:260:in `deliver'

     14: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/actionmailer-5.0.7.1/lib/action_mailer/base.rb:541:in `deliver_mail'

     13: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/notifications.rb:164:in `instrument'

     12: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'

     11: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/notifications.rb:164:in `block in instrument'

     10: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/actionmailer-5.0.7.1/lib/action_mailer/base.rb:543:in `block in deliver_mail'

      9: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:260:in `block in deliver'

      8: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:2159:in `do_delivery'

      7: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'

      6: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'

      5: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:518:in `start'

      4: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:565:in `do_start'

      3: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:728:in `authenticate'

      2: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:747:in `auth_login'

      1: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:981:in `check_auth_response'

Net::SMTPAuthenticationError (526 Authentication failure[0])

-------------------------------------------------------------------------------------

原因是文件/etc/gitlab/gitlab.rb 里面的git_user_email和smtp_user_name不一致,解决办法是:

sudo gedit /etc/gitlab/gitlab.rb

将下面内容修改到文件里面,重复的就注释掉:

gitlab_rails['smtp_user_name'] = "(你自己的邮箱前缀)@163.com"

gitlab_rails['gitlab_email_from'] = "(你自己的邮箱前缀)@163.com"

gitlab_rails['gitlab_email_reply_to'] = "(你自己的邮箱前缀)@163.com"

user["git_user_email"] = "(你自己的邮箱前缀)@163.com"

SMTP配置

1.修改gitlab.rb

sudo gedit /etc/gitlab/gitlab.rb

将下面内容加到文件里面:

gitlab_rails['smtp_enable'] = true

gitlab_rails['smtp_address'] = "smtp.163.com"

gitlab_rails['smtp_port'] = 25

gitlab_rails['smtp_user_name'] = "(你自己的邮箱前缀)@163.com"

gitlab_rails['smtp_password'] = "(163邮箱设置的授权码!授权码!授权码!)"

gitlab_rails['smtp_domain'] = "163.com"

gitlab_rails['smtp_authentication'] = "login"

gitlab_rails['smtp_enable_starttls_auto'] = true

gitlab_rails['smtp_tls'] = false

gitlab_rails['gitlab_email_from'] = "(你自己的邮箱前缀)@163.com"

gitlab_rails['gitlab_email_reply_to'] = "(你自己的邮箱前缀)@163.com"

user["git_user_email"] = "(你自己的邮箱前缀)@163.com"

这里一定要注意!!!注意!!!

smtp_user_name,gitlab_email_from,gitlab_email_reply_to和git_user_email建议一致,不然会出现:

SMTPFatalError (553 Mail from must equal authorized user)

SMTPAuthenticationError (535 Error: authentication failed)

只要内容没错,基本就不会有问题。

2.重新配置gitlab

sudo gitlab-ctl reconfigure

3.重启服务

sudo gitlab-ctl restart

完成。

相关文章
|
7天前
|
网络协议 数据安全/隐私保护 Windows
搭建个人hMailServer 邮件服务实现远程发送邮件
搭建个人hMailServer 邮件服务实现远程发送邮件
|
1月前
|
安全 API 网络安全
163邮箱 SMTP应该怎么配置发信使用?
163邮箱 SMTP应该怎么配置发信使用?
|
4月前
gitlab配置发送邮件
gitlab配置发送邮件
|
4月前
|
网络协议 数据安全/隐私保护 Windows
搭建个人hMailServer邮件服务实现远程发送邮件
搭建个人hMailServer邮件服务实现远程发送邮件
47 0
Gitea 的邮件通知
有这样的一个需求,当仓库中被推送或者更新代码的时候,希望在邮件中收到邮件通知。 Gitea 是可以实现这个功能的,但是在默认情况下这个功能是关闭的。
289 0
|
开发工具
gitlab配置邮箱推送通知
gitlab配置邮箱推送通知
457 0
gitlab配置邮箱推送通知
|
JavaScript PHP
你应该知道的最好Webmail邮件客户端,
1 . Kite Kite is an opensource replacement to Gmail. Kite is a webmail designed to look a lot like gmail and to be easily deployable on a single server.
3077 0
|
安全 应用服务中间件 数据安全/隐私保护
为 Confluence 6 配置发送邮件消息
如何配置 Confluence 向外发送邮件: 进入  > 基本配置(General Configuration) > 邮件服务器(Mail Servers)。
2375 0