Linux GitLab 邮件通知配置指南
一 准备与总体思路
二 编辑配置文件 gitlab.rb
# 启用 SMTP
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "your-smtp-user@example.com"
gitlab_rails['smtp_password'] = "your-smtp-password-or-app-password"
gitlab_rails['smtp_domain'] = "example.com"
gitlab_rails['smtp_authentication'] = "login" # 常见值:login/plain/cram_md5
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'peer' # 自签证书可用 'none'
# 发件人信息(部分邮箱对 From/Reply-To 有校验)
gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'
gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com'
三 应用配置并测试
gitlab-rails console
Notify.test_email('youremail@email.com', 'Hello World', 'This is a test message').deliver_now
四 常见方案与端口对照
| 方案 | 关键配置示例 |
|---|---|
| 外部 SMTP(推荐) | smtp_enable=true;端口587 + STARTTLS(smtp_enable_starttls_auto=true,smtp_tls=false)或端口465 + SSL(smtp_tls=true,smtp_enable_starttls_auto=false);填写 address/user/password/domain。 |
| 本机 Postfix 作为中继 | 在 /etc/postfix/main.cf 设置 relayhost(如 [smtp.xx.com]:587)、启用 SASL 认证(smtp_sasl_auth_enable=yes、smtp_sasl_password_maps 等),然后 GitLab 仍按外部 SMTP 方式配置为 localhost。 |
| Gmail | smtp_address=smtp.gmail.com;端口587;authentication=login;使用应用专用密码。 |
五 故障排查要点