如想用 SMTP 代替 Sendmail 发送email,添加如下相应邮箱服务商的配置到/etc/gitlab/gitlab.rb
, 然后运行gitlab-ctl reconfigure
使修改生效。 omnibus-gitlab还提供了测试发送邮件功能。
本文后面有一些常用的 SMTP配置示例,可以参考下。前往QQ企业邮箱配置
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.server"
gitlab_rails[‘smtp_port‘] = 465
gitlab_rails[‘smtp_user_name‘] = "smtp user"
gitlab_rails[‘smtp_password‘] = "smtp password"
gitlab_rails[‘smtp_domain‘] = "example.com"
gitlab_rails[‘smtp_authentication‘] = "login"
gitlab_rails[‘smtp_enable_starttls_auto‘] = true
gitlab_rails[‘smtp_openssl_verify_mode‘] = ‘peer‘
# 如果你使用的SMTP服务是默认的 ‘From:[email protected]‘
# 你可以修改这里的 ‘From‘ 的值。
gitlab_rails[‘gitlab_email_from‘] = ‘[email protected]‘
gitlab_rails[‘gitlab_email_reply_to‘] = ‘[email protected]‘
Example configuration 配置示例
SMTP on localhost
下面的配置仅仅是启用smtp,值为‘false‘则使用默认的设置(sendmail),启用smtp可用于不提供sendmail
接口或者与gitlab不兼容的sendmail
接口的运行MTA的本地服务器,如"Exim"。
gitlab_rails[‘smtp_enable‘] = true
QQ exmail (腾讯企业邮箱)
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.exmail.qq.com"
gitlab_rails[‘smtp_port‘] = 465
gitlab_rails[‘smtp_user_name‘] = "[email protected]"
gitlab_rails[‘smtp_password‘] = "password"
gitlab_rails[‘smtp_authentication‘] = "login"
gitlab_rails[‘smtp_enable_starttls_auto‘] = true
gitlab_rails[‘smtp_tls‘] = true
gitlab_rails[‘gitlab_email_from‘] = ‘[email protected]‘
Office 365
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.office365.com"
gitlab_rails[‘smtp_port‘] = 25
gitlab_rails[‘smtp_user_name‘] = "[email protected]"
gitlab_rails[‘smtp_password‘] = "secret"
gitlab_rails[‘smtp_domain‘] = "company.com"
gitlab_rails[‘smtp_authentication‘] = "login"
gitlab_rails[‘smtp_enable_starttls_auto‘] = true
gitlab_rails[‘smtp_tls‘] = false
Testing the SMTP configuration 测试配置是否成功
配置完成后可以用Rails控制台验证邮件是否能发送成功。 在GitLab服务器上,执行 gitlab-rails console
进入控制台。 然后在控制台提示符后输入下面的命令 发送一封测试邮件:
irb(main):003:0> Notify.test_email(‘[email protected]‘, ‘Message Subject‘, ‘Message Body‘).deliver_now
# 示例
Notify.test_email(‘收件人邮箱‘, ‘邮件标题‘, ‘邮件正文‘).deliver_now
### Email Settings
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.139.com"
gitlab_rails[‘smtp_port‘] = 25
gitlab_rails[‘smtp_user_name‘] = "15*****[email protected]"
gitlab_rails[‘smtp_password‘] = "ju*******23"
gitlab_rails[‘smtp_domain‘] = "foo.com"
gitlab_rails[‘smtp_authentication‘] = "login"
gitlab_rails[‘smtp_enable_starttls_auto‘] = true
gitlab_rails[‘smtp_tls‘] = false
# 如果你使用的SMTP服务是默认的 ‘From:[email protected]‘
# # 你可以修改这里的 ‘From‘ 的值。
gitlab_rails[‘gitlab_email_from‘] = ‘15*****[email protected]‘
gitlab_rails[‘gitlab_email_reply_to‘] = ‘15****[email protected]‘
host: 192.168.4.24
port: 80
https: false
重启服务后邮件链接成功转到gitlab服务器 192.168.4.24
参考:https://docs.gitlab.com.cn/omnibus/settings/smtp.html