在 CentOS 服务器上安装 Gitlab 完成后,我们还希望能通过邮箱来激活账号,或者发送一些系统通知。

这时候就需要配置邮箱了,推荐使用 SMTP 方式发信。

依然是修改 /etc/gitlab/gitlab.rb 配置文件:

### Email Settings
 gitlab_rails['gitlab_email_enabled'] = true
 gitlab_rails['gitlab_email_from'] = 'your_email@your_domain'
 gitlab_rails['gitlab_email_display_name'] = 'GitLab'
 gitlab_rails['gitlab_email_reply_to'] = 'your_email@your_domain'
# gitlab_rails['gitlab_email_subject_suffix'] = ''

### GitLab email server settings
###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
###! **Use smtp instead of sendmail/postfix.**

 gitlab_rails['smtp_enable'] = true
 gitlab_rails['smtp_address'] = "smtp.your_domain"
 gitlab_rails['smtp_port'] = 465
 gitlab_rails['smtp_user_name'] = "your_email@your_domain"
 gitlab_rails['smtp_password'] = "your_email_password"
 gitlab_rails['smtp_domain'] = "your_domain"
 gitlab_rails['smtp_authentication'] = "plain"
 gitlab_rails['smtp_enable_starttls_auto'] = true
 gitlab_rails['smtp_tls'] = true

###! **Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert'**
###! Docs: http://api.rubyonrails.org/classes/ActionMailer/Base.html
 gitlab_rails['smtp_openssl_verify_mode'] = 'none'

# gitlab_rails['smtp_ca_path'] = "/etc/ssl/certs"
# gitlab_rails['smtp_ca_file'] = "/etc/ssl/certs/ca-certificates.crt"
 user['git_user_email'] = "your_email@your_domain"

需要注意的是,如果你在这里填写明文密码,一定要将 gitlab_rails['smtp_authentication'] = "plain" 这一项设置正确,默认的值是 login,要修改为 plain

修改完成后执行 gitlab-ctl reconfigure

如果一切设置没有问题,那么在后台开启 确认邮件地址 功能后,新注册的用户即可收到激活邮件了。

gitlab.jpg