新搭建的gitlab ce服务器需要支持邮件通知功能,记录下过程。
公司内部自建的邮件服务器,使用Centos默认安装的Postfix+ExtMail搭建。
在此基础上配置gitlab的通知邮件。
1. 复制配置文件
1 | cd /home/git/gitlab |
2. 编辑配置文件
1 | sudo -u git -H vim config/initializers/smtp_setting.rb |
以下是完整的配置信息,真实信息已被修改
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtpActionMailer::Base.smtp_settings = {
#smtp服务器地址
address: “mail.company.com”,
#smtp服务端口
port: 25,
#内部邮件系统配置的邮箱
user_name: “gitlab@company.com”,
#邮箱的密码
password: “password”,
#邮件服务器的域名
domain: “company.com”,
authentication: :login,
enable_starttls_auto: false,
openssl_verify_mode: ‘none’ # See ActionMailer documentation for other possible options
}
end
3. 修改gitlab配置文件
1 | cd /home/git/gitlab |
## Email settings
# Email address used in the “From” field in mails sent by GitLab
#刚才配置的公司邮箱
email_from: gitlab@company.com
#发信人的名称,接收邮件时,显示在”发信人”里
email_display_name: GitLab CE
4. 重启gitlab服务
1 | service gitlab restart |
5. Web端配置
在Web上登录gitlab服务器,点击右上角的设置,如图:
在Email中填入刚才配置的邮箱地址,点击下方的Save changes,
然后会出现”Please click the link in the confirmation email before continuing,it was sent to …”的字样。
如下图:
登录到邮箱中,会受到gitlab服务器发送来的确认邮件,如图:
点击”Confirm my account”确认信息
回到gitlab修改通知邮件的地方,会看到邮件已经修改过来了。如下图:
此时,创建新用户,并制定真实存在的邮箱,用户会收到gitlab服务器发送的创建用户邮件。
6. 贴几个网上查到的163邮箱和腾讯邮箱的配置案例(没有验证过)
163邮箱
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: “smtp.163.com”,
port: 25,
user_name: “username”,
password: “123456”,
domain: “163.com”,
authentication: :plain,
enable_starttls_auto: true
}
end
腾讯邮箱
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: “smtp.exmail.qq.com”,
port: 25,
user_name: “username@company.com”,
password: “123456”,
domain: “smtp.qq.com”,
authentication: :plain,
enable_starttls_auto: true,
}
end
7. 其他说明
第二步中的配置使用于多数开源项目的邮件通知配置,至少公司的redmine的配置和这样一样;
此方法仅在gitlab 7.X版本上做过测试,不保证其他版本可用;
转载于:https://blog.51cto.com/5404542/1730747