CI/CD-Gitlab配置腾讯企业邮箱
一、环境介绍
- 研发团队想要使用gitlab+企业邮箱实现开发人员可以注册gitlab和gitlab代码拉取或变动时实现邮件通知功能。
- centos 7.5
- gitlab版本 - GitLab: 11.6.5 (237bddc)
二、配置gitlab实现发送邮件功能
1.编辑配置文件
~]# vim /etc/gitlab/gitlab.rb #13行左右
external_url 'http://192.168.20.218'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "gitlab@xxxxx.com"
gitlab_rails['smtp_password'] = "XXadm01$"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
#gitlab_rails['smtp_authentication'] = "plain"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['gitlab_email_from'] = "gitlab@xxxxxx.com"
gitlab_rails['smtp_enable_starttls_auto'] = true
user['git_user_email'] = "gitlab@xxxxxxx.com"
gitlab_rails['smtp_tls'] = true
2、检查配置文件是否正确
~]# gitlab-ctl check-config
3、重新启动gitlab
~]# gitlab-ctl restart
4、log没有给出错误信息。那就直接开大招
~]# gitlab-rails console production
irb(main):001:0> ActionMailer::Base.delivery_method
=> :sendmail
#发现开启邮件操作未生效
5、如果不是smtp则需要配置
~]# gitlab-ctl reconfigure
6、再次查看
~]# gitlab-rails console
irb(main):002:0> ActionMailer::Base.delivery_method
=> :smtp
#确保method为smtp,错了就是配置写错了或者没被正确加载
irb(main):003:0> ActionMailer::Base.smtp_settings
=> {:authentication=>:login, :address=>"smtp.exmail.qq.com", :port=>465, :user_name=>"gitlab@.com", :password=>"XXadm01$", :dom
7、邮件测试 发送测试邮件,此时会打印详细错误
irb(main):005:0> Notify.test_email('zhe.dai@xxxxxxx.com', 'Hello World', 'This is a test message').deliver_now
Notify#test_email: processed outbound mail in 442.6ms
Sent mail to zhe.dai@xxxxxxx.com (2478.2ms)
Date: Wed, 30 Oct 2019 10:49:16 +0800
From: GitLab <gitlab@xxxxxxx.com>
Reply-To: GitLab <noreply@192.168.20.218>
To: zhe.dai@xiaoyangedu.com
Message-ID: <5db8fa2c477c0_2d9b3ff0515dc628473d6@dev-linux-gitlab.com.mail>
Subject: Hello World
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>This is a test message</p></body></html>
=> #<Mail::Message:70301019034700, Multipart: false, Headers: <Date: Wed, 30 Oct 2019 10:49:16 +0800>, <From: GitLab <gitlab@xxxxxxx.com>>, <Reply-To: GitLab <noreply@192.168.20.218>>, <To: zhe.dai@xxxxxxx.com>, <Message-ID: <5db8fa2c477c0_2d9b3ff0515dc628473d6@dev-linux-gitlab.com.mail>>, <Subject: Hello World>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
#注意:此时真相大白,用第三方客户端登录QQ邮箱需要用授权码代替密码
8、gitlab页面操作
向往的地方很远,喜欢的东西很贵,这就是我努力的目标。