1. 首先是拷贝Gitlab自带的example
1
2
|
cd
/home/git/gitlab
sudo
-u git -H
cp
config
/initializers/smtp_settings
.rb.sample config
/initializers/smtp_settings
.rb
|
2. 然后用我们自己的邮箱替换example中的邮箱
1
|
sudo
-u git -H vim config
/initializers/smtp_settings
.rb
|
这里提供163和腾讯企业邮箱两种配置方式,注意将下面的123456替换成自己的密码
163:
1
2
3
4
5
6
7
8
9
10
11
12
|
if
Rails.
env
.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address:
"smtp.163.com"
,
port: 25,
user_name:
"wpgitlab"
,
password:
"123456"
,
domain:
"163.com"
,
authentication: :plain,
enable_starttls_auto:
true
}
end
|
腾讯企业邮箱:
1
2
3
4
5
6
7
8
9
10
11
12
|
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:
"wangpeng@scnee.com"
,
password:
"123456"
,
domain:
"smtp.qq.com"
,
authentication: :plain,
enable_starttls_auto:
true
,
}
end
|
3. 修改gitlab.yml
1
2
|
cd
/home/git/gitlab
sudo
-u git -H vim config
/gitlab
.yml
|
将默认邮箱修改为自己的邮箱
163:
1
2
3
|
## Email settings
# Email address used in the "From" field in mails sent by GitLab
email_from: wpgit@163.com
|
腾讯企业邮箱:
1
2
3
|
## Email settings
# Email address used in the "From" field in mails sent by GitLab
email_from: wangpeng@scnee.com
|
4. 修改后。重启gitlab
1
|
sudo
service gitlab restart
|
注意事项:
1. 不需要修改 config/environments/production.rb,网上的其他文章说要修改这个文件可能是针对老版本的,gitlab7.0不需要修改这个文件(已测试)。
2. 腾讯企业邮箱不能使用其帮助网页上所写的465端口。设置了openssl_verify_mode也没有作用。若有人试验成功,请告知我,谢谢。
gitlab 发邮件时模式显示名称为GitLab,如果要修改方法如下:
You can see the sender
function in app/mailers/notify.rb#L30
:
# The default email address to send emails from
def default_sender_address
address = Mail::Address.new(Gitlab.config.gitlab.email_from)
address.display_name = "GitLab"
address
end
# Return an email address that displays the name of the sender.
# Only the displayed name changes; the actual email address is always the same.
def sender(sender_id)
if sender = User.find(sender_id)
address = default_sender_address
address.display_name = sender.name
address.format
end
end