Linux學習19-gitlab配置郵箱postfix(新用戶激活郵件)


前言

gitlab新增新用戶有兩種方式,第一種可以用戶主動注冊(自己設置密碼);第二種也可以通過root管理員用戶直接添加用戶,發個郵件到用戶的郵箱里,收到郵件后激活。
如果是第二種方式添加新用戶的話,就需要配置gitlab郵箱了。
相關環境
postfix
gitlab

postfix配置

前面一篇已經安裝好postfix相關環境https://www.cnblogs.com/yoyoketang/p/10272544.html
先輸入systemctl status postfix確定postfix是啟動狀態,看到 Active: active (running)說明,已經啟動了

[root@yoyo ~]# 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 yoyo postfix/smtp[19300]: 165D54046D: to=<admin@example.com>, relay=none, delay=7...out)
Jan 18 09:39:07 yoyo postfix/qmgr[1631]: 2A0804044C: from=<gitlab@47.104.190.48>, size=7538, nrcp...ive)
Jan 18 09:39:37 yoyo postfix/smtp[20356]: connect to example.com[93.184.216.34]:25: Connection timed out
Jan 18 09:39:37 yoyo postfix/smtp[20356]: 2A0804044C: to=<admin@example.com>, relay=none, delay=8...out)
Jan 18 10:39:07 yoyo postfix/qmgr[1631]: 165D54046D: from=<gitlab@47.104.190.48>, size=7547, nrcp...ive)
Jan 18 10:39:37 yoyo postfix/smtp[26711]: connect to example.com[93.184.216.34]:25: Connection timed out
Jan 18 10:39:37 yoyo postfix/smtp[26711]: 165D54046D: to=<admin@example.com>, relay=none, delay=7...out)
Jan 18 10:49:07 yoyo postfix/qmgr[1631]: 2A0804044C: from=<gitlab@47.104.190.48>, size=7538, nrcp...ive)
Jan 18 10:49:37 yoyo postfix/smtp[27758]: connect to example.com[93.184.216.34]:25: Connection timed out
Jan 18 10:49:37 yoyo 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'] = "2833xxx@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('yoyo_你自己隨便郵箱@qq.com', '郵件標題_test', '郵件正文_test').deliver_now

[root@yoyo gitlab]# gitlab-rails console
Loading production environment (Rails 4.2.8)
irb(main):001:0> Notify.test_email('yoyo_******@qq.com', '郵件標題_test', '郵件正文_test').deliver_now 

Notify#test_email: processed outbound mail in 1.2ms

Sent mail to yoyo_******@qq.com(1375.0ms)
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: =?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首頁,自己注冊

django交流QQ群:779429633


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM