编辑配置文件gitlab.rb

  • 配置文件的位置一般在/etc/gitlab/gitlab.rb
  • 有2个地方需要配置
### Email Settings
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '你的QQ邮箱'
gitlab_rails['gitlab_email_display_name'] = '陈洋'
gitlab_rails['gitlab_email_reply_to'] = '你的QQ邮箱'
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.qq.com"
gitlab_rails['smtp_port'] = 465 
gitlab_rails['smtp_user_name'] = "你的QQ邮箱"
gitlab_rails['smtp_password'] = "授权码,不是邮箱密码" 
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

重启gitlab服务

gitlab-ctl restart

测试邮件发送

root@192:/# gitlab-rails console
irb(main):002:0> Notify.test_email('961363629@qq.com', 'Message Subject', 'Message Body').deliver_now

注意点

测试邮件时报错501

Net::SMTPSyntaxError: 501 mail from address must be same as authorization user

原因:配置文件gitlab.rb中### Email Settings没有设置邮箱地址,意思就是发送邮件的地址和SMTP认证的账号必须一致
解决办法:配置好### Email Settings即可

测试邮件时报错SSLError

原因:此类报错通常是SMTP服务器没有使用SSL,但是配置却开启了
解决办法:注释掉以下配置
# gitlab_rails['smtp_enable_starttls_auto'] = true
# gitlab_rails['smtp_tls'] = true
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐