Skip to content

GitLab 配置邮箱服务

1)开通 SMTP 服务,获取**授权密码**(自行百度)

2)编辑 /etc/gitlab/gitlab.rb 文件添加 smtp 相关配置,以 163 邮箱为例

$ grep -E 'smtp|user|email' gitlab.rb | grep -vE '^#|^$'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "final_ning@163.com"
gitlab_rails['smtp_password'] = "BBPCSDZMDLKHQNZZ"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_pool'] = true
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'final_ning@163.com'
gitlab_rails['gitlab_email_display_name'] = 'GitLab'
gitlab_rails['gitlab_email_reply_to'] = 'final_ning@163.com'
gitlab_rails['gitlab_email_subject_suffix'] = ''
user['git_user_name'] = "GitLab"
user['git_user_email'] = "final_ning@163.com"

3)重置配置并重启服务

$ docker exec -it gitlab-ce gitlab-ctl reconfigure
$ docker exec -it gitlab-ce gitlab-ctl restart

4)邮件服务测试

$ docker exec -it gitlab-ce bash
root@188:/# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-linux]
 GitLab:       15.9.1 (de8f6619031) FOSS
 GitLab Shell: 14.17.0
 PostgreSQL:   13.8
------------------------------------------------------------[ booted in 43.72s ]
Loading production environment (Rails 6.1.7.2)
irb(main):001:0> Notify.test_email('228003666@qq.com','email title','email content desc').deliver_now
Delivered mail 6401a031f7a1_56d34880831@188.188.3.3.mail (620.8ms)
=> #<Mail::Message:295860, Multipart: false, Headers: <Date: Fri, 03 Mar 2023 15:22:25 +0800>, <From: GitLab <final_ning@163.com>>, <Reply-To: GitLab <noreply@188.188.3.3>>, <To: 228003666@qq.com>, <Message-ID: <6401a031f7a1_56d34880831@188.188.3.3.mail>>, <Subject: email 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>>
irb(main):002:0> exit
root@188:/# exit
exit