gitlab服務器郵箱配置
如想用 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:gitlab@localhost‘
# 你可以修改這裏的 ‘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
實際配置使用139郵箱: vim /etc/gitlab/gitlab.rb
### 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:gitlab@localhost‘
# # 你可以修改這裏的 ‘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
gitlab服務器郵箱配置