為GitLab配置郵件服務

tinys發表於2019-03-06

修改配置檔案:/etc/gitlab/gitlab.rb

################################################################################
## gitlab.yml configuration
##! Docs: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/gitlab.yml.md
################################################################################
# gitlab_rails['gitlab_ssh_host'] = 'ssh.host_example.com'
# gitlab_rails['time_zone'] = 'UTC'

### Email Settings
 gitlab_rails['gitlab_email_enabled'] = true
 gitlab_rails['gitlab_email_from'] = 'gitlab@xxx.com.cn'
 gitlab_rails['gitlab_email_display_name'] = 'xx GitLab'
# gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com'
# 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.exmail.qq.com"
 gitlab_rails['smtp_port'] = 465
 gitlab_rails['smtp_user_name'] = "xxzz@xx.com
 gitlab_rails['smtp_password'] = "xxx"
 gitlab_rails['smtp_domain'] = "exmail.qq.com"
 gitlab_rails['smtp_authentication'] = "login"
 gitlab_rails['smtp_enable_starttls_auto'] = true
 gitlab_rails['smtp_tls'] = true

################################################################################
## GitLab User Settings
##! Modify default git user.
##! Docs: https://docs.gitlab.com/omnibus/settings/configuration.html#changing-the-name-of-the-git-user-group
################################################################################

# user['username'] = "git"
# user['group'] = "git"
# user['uid'] = nil
# user['gid'] = nil

##! The shell for the git user
# user['shell'] = "/bin/sh"

##! The home directory for the git user
# user['home'] = "/var/opt/gitlab"

# user['git_user_name'] = "GitLab"
 user['git_user_email'] = "gitlab@xxx.com.cn"

執行重新配置命令:

gitlab-ctl reconfigure

然後重新啟動gitlab:

gitlab-ctl restart

所有步驟執行完成,然後我們可以測試一下,配置是否成功!

a.首先進入gitlab控制檯

gitlab-rails console

b.執行如下命令,傳送測試郵件

Notify.test_email("8080@qq.com","主題","正文").deliver_now

收到郵件,大功告成!

相關文章