共计 1731 个字符,预计需要花费 5 分钟才能阅读完成。
[v_act]说明:Gitlab可以配置外部SMTP邮箱服务器来实现内部邮件提醒功能,此处我们演示的是阿里云免费企业邮(mxhichina.com)SMTP邮箱服务器。[/v_act]
1、编辑修改配置文件/etc/gitlab/gitlab.rb定义SMTP参数
gitlab_rails['gitlab_email_from'] = 'postmaster@ityww.cn'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.mxhichina.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "postmaster@ityww.cn"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_domain'] = "mxhichina.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
2、配置后需执行命令gitlab-ctl reconfigure重载配置文件
Running handlers:
Running handlers complete
Chef Client finished, 17/600 resources updated in 55 seconds
gitlab Reconfigured!
3、测试发送邮件验证SMTP配置,邮件发送成功表示配成正确。
a)执行命令gitlab-rails console进入控制台
[root@izuf6fy69k7l7e20jogcj7z gitlab]# gitlab-rails console
-------------------------------------------------------------------------------------
GitLab: 11.1.4 (63daf37)
GitLab Shell: 7.1.4
postgresql: 9.6.8
-------------------------------------------------------------------------------------
Loading production environment (Rails 4.2.10)
irb(main):001:0>
b)执行测试命令Notify.test_email(‘destination_email@address.com’, ‘Message Subject’, ‘Message Body’).deliver_now验证
irb(main):001:0> Notify.test_email('yvan.lu@ityww.cn','Testmail','test').deliver_now
Notify#test_email: processed outbound mail in 401.8ms
Sent mail to yvan.lu@ityww.cn (385.5ms)
Date: Wed, 08 Aug 2018 22:23:35 +0800
From: GitLab
Reply-To: GitLab
To: yvan.lu@ityww.cn
Message-ID: <5b7c2067b3fd_786c3fa07a1daf889661b@izuf6fy69k7l7e20jogcj7z.mail>
Subject: Testmail
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All
test
=> #, >, >, , >, , , , , , >
irb(main):002:0>
[v_blue]更多邮箱配置请参考官方文档:https://docs.gitlab.com/omnibus/settings/smtp.html#smtp-settings[/v_blue]
正文完
发表至: Git-Gitlab
2018-08-08