gitlab配置邮箱postfix

Posted jason89

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gitlab配置邮箱postfix相关的知识,希望对你有一定的参考价值。

前言

gitlab新增新用户有两种方式,第一种可以用户主动注册(自己设置密码)第二种也可以通过root管理员用户直接添加用户,发个邮件到用户的邮箱里,收到邮件后激活。
如果是第二种方式添加新用户的话,就需要配置gitlab邮箱了。
相关环境
postfix
gitlab

postfix配置

先输入systemctl status postfix确定postfix是启动状态,看到 Active: active (running)说明,已经启动了

# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-01-17 10:24:03 CST; 1 day 1h ago
 Main PID: 1629 (master)
   CGroup: /system.slice/postfix.service
           ├─ 1629 /usr/libexec/postfix/master -w
           ├─ 1631 qmgr -l -t unix -u
           └─31352 pickup -l -t unix -u

Jan 18 09:29:37  postfix/smtp[19300]: 165D54046D: to=<[email protected]>, relay=none, delay=7...out)
Jan 18 09:39:07  postfix/qmgr[1631]: 2A0804044C: from=<[email protected]47.104.190.48>, size=7538, nrcp...ive)
Jan 18 09:39:37  postfix/smtp[20356]: connect to example.com[93.184.216.34]:25: Connection timed out
Jan 18 09:39:37  postfix/smtp[20356]: 2A0804044C: to=<[email protected]>, relay=none, delay=8...out)
Jan 18 10:39:07  postfix/qmgr[1631]: 165D54046D: from=<[email protected]47.104.190.48>, size=7547, nrcp...ive)
Jan 18 10:39:37  postfix/smtp[26711]: connect to example.com[93.184.216.34]:25: Connection timed out
Jan 18 10:39:37  postfix/smtp[26711]: 165D54046D: to=<[email protected]>, relay=none, delay=7...out)
Jan 18 10:49:07  postfix/qmgr[1631]: 2A0804044C: from=<[email protected]47.104.190.48>, size=7538, nrcp...ive)
Jan 18 10:49:37  postfix/smtp[27758]: connect to example.com[93.184.216.34]:25: Connection timed out
Jan 18 10:49:37  postfix/smtp[27758]: 2A0804044C: to=<[email protected]>, relay=none, delay=8...out)
Hint: Some lines were ellipsized, use -l to show in full.

vim打开gitlab的配置文件:/etc/gitlab/gitlab.rb,新增以下内容

  • smtp_addressQQ邮箱服务器是smtp.qq.com
  • smtp_port端口465 (注意,不要用25端口)
  • smtp_user_name 配置自己的QQ号
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.qq.com"
gitlab_rails[‘smtp_port‘] = 465
gitlab_rails[‘smtp_user_name‘] = "[email protected]"  # 你自己QQ号
gitlab_rails[‘smtp_password‘] = "*************"             # QQ授权码
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_rails[‘gitlab_email_from‘] = [email protected]# 你自己QQ号

注意:这里的qq密码是授权码
打开QQ邮箱-设置-账户-帐户安全-开启服务-POP3/SMTP服务-生成授权码-发个短信

技术分享图片

配置完成后执行gitlab-ctl reconfigure 让配置生效

gitlab-ctl reconfigure

测试邮箱

执行 gitlab-rails console进入控制台交互界面, 然后在控制台提示符后输入下面内容发送一封测试邮件,测试完成后exit()退出。

gitlab-rails console
Notify.test_email(‘你自己随便邮箱@qq.com‘, ‘邮件标题_test‘, ‘邮件正文_test‘).deliver_now

[[email protected] gitlab]# gitlab-rails console
Loading production environment (Rails 4.2.8)
irb(main):001:0> Notify.test_email(‘******@qq.com‘, ‘邮件标题_test‘, ‘邮件正文_test‘).deliver_now 

Notify#test_email: processed outbound mail in 1.2ms

Sent mail to ******@qq.com(1375.0ms)
Date: Fri, 18 Jan 2019 13:58:24 +0800
From: GitLab <[email protected]>
Reply-To: GitLab <[email protected]>
To: ******@qq.com
Message-ID: <[email protected]>
Subject: =?UTF-8?Q?=E9=82=AE=E7=AE=B1=E4=B8=BB=E9=A2=98=5Ftest?=
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www=
.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>=E9=82=AE=E7=AE=B1=E6=AD=A3=E6=96=87_test</p></body></html=
>

=> #<Mail::Message:70259829672900, Multipart: false, Headers: <Date: Fri, 18 Jan 2019 13:58:24 +0800>, 
<From: GitLab <[email protected]qq.com>>, <Reply-To: GitLab <[email protected]47.104.190.48>>, 
<To: yoyo_******@qq.com>, <Message-ID: <[email protected]yoyo.mail>>, 
<Subject: 邮箱主题_test>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, 
<Content-Transfer-Encoding: quoted-printable>, 
<Auto-Submitted: auto-generated>, 
<X-Auto-Response-Suppress: All>>
irb(main):006:0> exit()  # 退出

技术分享图片

新增新账号

使用root管理员用户登录gitlab后台-> Users ->New user

技术分享图片

填写完用户信息后,点 Crear user按钮,填的邮箱地址就会收到激活邮件

激动邮箱,设置登录密码,就可以登录gitlab了

技术分享图片

新用户自己注册

新用户也可以直接打开gitlab首页,自己注册

技术分享图片

 
 
 






以上是关于gitlab配置邮箱postfix的主要内容,如果未能解决你的问题,请参考以下文章

Git代码仓库管理系统的配置方法之:Gitlab

SUS系统 postfix邮箱设置

Postfix邮箱服务搭建

postfix邮箱服务

centos 7 postfix配置163邮箱发送邮件

gitlab安装