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 [email protected] (1.7ms)

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

From: GitLab

Reply-To: GitLab

To: [email protected]

Message-ID: <[email protected]>

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('[email protected]', 'title', 'body').deliver_now

Notify#test_email: processed outbound mail in 566.8ms

Sent mail to [email protected] (5412.3ms)

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

From: GitLab

Reply-To: GitLab

To: [email protected]

Message-ID: <[email protected]>

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

 

完成。

你可能感兴趣的:(git)