gitlab 设置邮件 SMTP

版权声明:本文为博主夏日辉的原创文章,未经博主允许不得转载。 https://blog.csdn.net/shanpenghui/article/details/89175390

安装gitlab的时候没有设置和STMP邮件,重新装的时候遇到点问题,记录一下。

  1. 553问题

Net::SMTPFatalError (553 Mail from must equal authorized user)
终端提示如下:

Date: Wed, 10 Apr 2019 10:09:22 +0800
From: GitLab <¥%……&×(@163.com>
Reply-To: GitLab <¥%……&×()@163.com>
To: #¥%……&×@qq.com
Message-ID: <[email protected]>
Subject: test
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>test body</p></body></html>

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/base.rb:541:in `deliver_mail'
       15: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/notifications.rb:164:in `instrument'
       14: 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'
       13: 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'
       12: 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'
       11: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:260:in `block in deliver'
       10: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:2159:in `do_delivery'
        9: 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!'
        8: 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'
        7: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:519:in `start'
        6: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:101:in `block in deliver!'
        5: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp_connection.rb:54:in `deliver!'
        4: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:658:in `send_message'
        3: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:837:in `mailfrom'
        2: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:937:in `getok'
        1: from /opt/gitlab/embedded/lib/ruby/2.5.0/net/smtp.rb:969:in `check_response'
Net::SMTPFatalError (553 Mail from must equal authorized user)

原因是文件/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"
  1. 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
  1. 完成。

猜你喜欢

转载自blog.csdn.net/shanpenghui/article/details/89175390
今日推荐