在CentOS上配置GitLab以使用外部郵件服務器發送通知郵件,可以按照以下步驟進行:
首先,你需要安裝Postfix作為郵件傳輸代理(MTA)。
sudo yum install postfix
在安裝過程中,選擇“Internet Site”作為配置類型,并設置系統郵件名稱(通常是你的域名)。
編輯Postfix的主配置文件 /etc/postfix/main.cf
:
sudo vi /etc/postfix/main.cf
添加或修改以下配置:
myhostname = yourdomain.com
myorigin = $myhostname
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relayhost =
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
保存并退出編輯器。
sudo systemctl start postfix
sudo systemctl enable postfix
編輯GitLab的配置文件 /etc/gitlab/gitlab.rb
:
sudo vi /etc/gitlab/gitlab.rb
找到并修改以下配置項:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.yourmailserver.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "your-email@example.com"
gitlab_rails['smtp_password'] = "your-email-password"
gitlab_rails['smtp_domain'] = "yourdomain.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
確保將 smtp.yourmailserver.com
, your-email@example.com
, your-email-password
, 和 yourdomain.com
替換為你的實際郵件服務器信息。
運行以下命令以應用更改:
sudo gitlab-ctl reconfigure
發送一封測試郵件以確保配置正確:
sudo gitlab-rake gitlab:email:test
如果一切配置正確,你應該會收到一封測試郵件。
smtp_enable_starttls_auto
設置。通過以上步驟,你應該能夠在CentOS上成功配置GitLab以使用外部郵件服務器發送通知郵件。