码迷,mamicode.com
首页 > 其他好文 > 详细

gitlab配置邮箱postfix

时间:2019-01-27 19:28:05      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:界面   blog   Fix   keyword   headers   pass   generated   bubuko   show   

前言

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=<admin@example.com>, relay=none, delay=7...out)
Jan 18 09:39:07  postfix/qmgr[1631]: 2A0804044C: from=<gitlab@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=<admin@example.com>, relay=none, delay=8...out)
Jan 18 10:39:07  postfix/qmgr[1631]: 165D54046D: from=<gitlab@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=<admin@example.com>, relay=none, delay=7...out)
Jan 18 10:49:07  postfix/qmgr[1631]: 2A0804044C: from=<gitlab@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=<admin@example.com>, 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‘] = "xxx@qq.com"  # 你自己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‘] = 2833xxx@qq.com‘   # 你自己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

[root@jason 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 <xxx@qq.com>
Reply-To: GitLab <noreply@47.104.190.48>
To: ******@qq.com
Message-ID: <5c416b00e10ef_3e8f3fe6bd9db11817659@yoyo.mail>
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 <2833xxx@qq.com>>, <Reply-To: GitLab <noreply@47.104.190.48>>, 
<To: yoyo_******@qq.com>, <Message-ID: <5c416b00e10ef_3e8f3fe6bd9db11817659@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

标签:界面   blog   Fix   keyword   headers   pass   generated   bubuko   show   

原文地址:https://www.cnblogs.com/jason89/p/10327289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!