gitlab邮件配置

配置smtp邮件发送
注意:要开启邮件服务器
如:QQ在邮箱 账户 中 开启smtp等协议
腾讯企业邮箱 在 设置 客户端设置开启
vim /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25          #这里我用了465,25端口阿里云是封掉的
gitlab_rails['smtp_user_name'] = "xxuser@163.com"
gitlab_rails['smtp_password'] = "xxpassword"     #开通SMTP服务时生成的客户端授权码,或者QQ邮箱里面授权码而不是邮箱的登录密码
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true

##修改gitlab配置的发信人,两个必须一致,否则可能出现553报错
gitlab_rails['gitlab_email_from'] = "xxuser@163.com"
user["git_user_email"] = "xxuser@163.com"
配置完成后重载gitlab配置:gitlab-ctl reconfigure

邮箱设置 完成后运行以下命令测试:

# gitlab-rails console
输入:
Notify.test_email('destination_email@address.com', 'Message Subject', 'Message Body').deliver_now
查看测试结果:
[root@gitlab ~]#  gitlab-rails console
-------------------------------------------------------------------------------------
 GitLab:       11.3.5-ee (7b10203)
 GitLab Shell: 8.3.3
 postgresql:   9.6.8
-------------------------------------------------------------------------------------

Loading production environment (Rails 4.2.10)
irb(main):001:0> 
irb(main):002:0* 
irb(main):003:0* Notify.test_email('xxxxxx@qq.com','title','body').deliver_now

Notify#test_email: processed outbound mail in 680.8ms

Sent mail to xxxxxx@qq.com (365.9ms)
Date: Sun, 04 Aug 2019 10:28:04 +0800
From: GitLab <gitlabadmin@allen.com>
Reply-To: GitLab <gitlabadmin@allen.com>
To: xxxxxx@qq.com
Message-ID: <5d4642b44a851_47e03fb0e04daf8c7887b@gitlab.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

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

=> #<Mail::Message:70028537778620, Multipart: false, Headers: <Date: Sun, 04 Aug 2019 10:28:04 +0800>, <From: GitLab <gitlabadmin@allen.com>>, <Reply-To: GitLab <gitlabadmin@allen.com>>, <To: xxxxxx@qq.com>, <Message-ID: <5d4642b44a851_47e03fb0e04daf8c7887b@gitlab.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>>
在测试的时候可以另外打开一个终端,执行如下命令来查看实时日志:gitlab-ctl tail

版权声明:
作者:allenjol
链接:https://www.ayunw.cn/archives/456
来源:爱生活,爱运维
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>