Gitlab新建用戶無(wú)法收到郵件的問(wèn)題解決辦法
前言
這個(gè)問(wèn)題網(wǎng)上解決的帖子很多,根本原因就是配置錯(cuò)誤,修改好配置就可以了,我也沒(méi)有其他的更加新奇的解決辦法,之所以再總結(jié)一遍只是為了自己統(tǒng)一查找方便,同時(shí)把一些差異點(diǎn)記錄一下,因?yàn)榘姹竞瓦\(yùn)行環(huán)境的不同,可能跟網(wǎng)上的解決方案有一點(diǎn)點(diǎn)差異,先寫(xiě)答案再聊不同吧。
解決方案
開(kāi)啟企業(yè)微信郵箱(QQ郵箱、163郵箱亦可)的POP3/SMTP服務(wù),獲取授權(quán)碼
修改gitlab的配置文件
/etc/gitlab/gitlab.rb如下
gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.exmail.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "gitlab@gameup.com" gitlab_rails['smtp_password'] = "授權(quán)碼" gitlab_rails['smtp_domain'] = "exmail.qq.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = false gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_enabled'] = true gitlab_rails['gitlab_email_from'] = 'gitlab@gameup.com' gitlab_rails['gitlab_email_display_name'] = 'Gitlab'
重新加載配置生效
gitlab-ctl reconfigure,等待執(zhí)行完成利用gitlab測(cè)試配置是否成功
- 執(zhí)行 gitlab-rails console進(jìn)入控制臺(tái),我的機(jī)器性能較差,多等一會(huì)看到命令提示符
 - 輸入后面面的命令 
Notify.test_email('收件人郵箱', '郵件標(biāo)題', '正文').deliver_now發(fā)送一封測(cè)試郵件 - 若成功過(guò)則收到測(cè)試郵件,失敗則會(huì)在控制臺(tái)顯示錯(cuò)誤消息,根據(jù)錯(cuò)誤信息檢查和修改配置即可
 
遇到的錯(cuò)誤
我修改配置的旅程也不是一帆風(fēng)順的,期間也遇到的了幾個(gè)錯(cuò)誤,都是在 Notify.test_email 測(cè)試之后發(fā)現(xiàn)有問(wèn)題,逐步修改的
域名解析問(wèn)題
Notify.test_email('shz@gamegu.com', 'Test Email', 'This is a test email from GitLab').deliver_now
--------------------------------------------------------------------------------
 Ruby:         ruby 3.2.5 (2024-07-26 revision 31d0f1a2e7) [x86_64-linux]
 GitLab:       17.5.1 (e8dca573167) FOSS
 GitLab Shell: 14.39.0
 PostgreSQL:   14.11
------------------------------------------------------------[ booted in 61.07s ]
Loading production environment (Rails 7.0.8.4)
Delivered mail 67248a5c847e9_6f32fe445660@gitlab.gamegu.com.mail (20023.7ms)
/opt/gitlab/embedded/lib/ruby/3.2.0/socket.rb:231:in getaddrinfo': getaddrinfo: Temporary failure in name resolution (SocketError)
        from /opt/gitlab/embedded/lib/ruby/3.2.0/socket.rb:231:in foreach'
        from /opt/gitlab/embedded/lib/ruby/3.2.0/socket.rb:635:in tcp'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:643:in tcp_socket'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:656:in do_start'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:611:in start'
        from /opt/gitlab/embedded/service/gitlab-rails/config/initializers/mail_starttls_patch.rb:53:in start_smtp_session'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb:100:in deliver!'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:2145:in do_delivery'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in block in deliver'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/base.rb:588:in block in deliver_mail'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications.rb:206:in block in instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications/instrumenter.rb:24:in instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications.rb:206:in instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/base.rb:586:in deliver_mail'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in deliver'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/message_delivery.rb:119:in block in deliver_now'
        ... 15 levels...
irb(main):002:0>
解決辦法
修改 /etc/resolv.conf 來(lái)指定自己服務(wù)器的DNS,通用的可以使用 nameserver 8.8.8.8
郵箱認(rèn)證問(wèn)題
/opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:1076:in check_response': 501 mail from address must be same as authorization user (Net::SMTPSyntaxError)
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:1044:in getok'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:945:in mailfrom'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:767:in send_message'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp_connection.rb:53:in deliver!'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb:101:in block in deliver!'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:612:in start'
        from /opt/gitlab/embedded/service/gitlab-rails/config/initializers/mail_starttls_patch.rb:53:in start_smtp_session'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb:100:in deliver!'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:2145:in do_delivery'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in block in deliver'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/base.rb:588:in block in deliver_mail'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications.rb:206:in block in instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications/instrumenter.rb:24:in instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications.rb:206:in instrument'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/base.rb:586:in deliver_mail'
        from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in deliver'
        ... 16 levels...
解決方案
smtp 配置中應(yīng)該填寫(xiě)正確的郵箱和授權(quán)碼,同時(shí) /etc/gitlab/gitlab.rb 中設(shè)置 gitlab_rails['gitlab_email_from'] 與 gitlab_rails['smtp_user_name'] 一致
端口配置互斥
gitlab_rails['smtp_tls'] and gitlab_rails['smtp_enable_starttls_auto'] are mutually exclusive. Set one of them to false. SMTP providers usually use port 465 for TLS and port 587 for STARTTLS.
解決方案
這個(gè)錯(cuò)誤表明在 GitLab 的配置文件中同時(shí)啟用了 smtp_tls 和 smtp_enable_starttls_auto 選項(xiàng),但它們是互斥的,只能選擇其中一個(gè)設(shè)置為 true,如果使用 TLS(通常是端口 465)僅將 smtp_tls 選項(xiàng)設(shè)置為 true,如果使用 STARTTLS(通常是端口 587)只能將 smtp_enable_starttls_auto 設(shè)置為true。
關(guān)于gitlab的參數(shù),有一個(gè)external_url 表示gitlab的訪問(wèn)域名,可以配置為 external_url 'http://gitlab.gameup.com',而這個(gè)域名也可以在定義容器時(shí)通過(guò) --hostname 指定
運(yùn)行環(huán)境
我的Gitlab不是在服務(wù)器上直接安裝的,而是通過(guò)Docker安裝的gitlab鏡像,服務(wù)器是CentOS7系統(tǒng),gitlab組件相關(guān)版本如下:
Components
GitLab v17.5.1
GitLab Shell 14.39.0
GitLab Workhorse v17.5.1
GitLab API v4
GitLab KAS 17.5.1
Ruby 3.2.5p208
Rails 7.0.8.4
PostgreSQL (main) 14.11
PostgreSQL (ci) 14.11
Redis 7.0.15
正因?yàn)槲沂峭ㄟ^(guò)Dokcer安裝的,所以上面的很多命令需要到容器中執(zhí)行,也就是得先執(zhí)行 docker exec -it gitlab /bin/bash
而通過(guò)Docker安裝gitlab的命令也列舉一下:
docker run --detach \ --hostname gitlab.gameup.com \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ --restart always \ --volume /export/docker/gitlab/config:/etc/gitlab \ --volume /export/docker/gitlab/logs:/var/log/gitlab \ --volume /export/docker/gitlab/data:/var/opt/gitlab \ registry.cn-hangzhou.aliyuncs.com/z5z/gitlab-ce:latest
不要問(wèn)我這個(gè)鏡像名字為什么這樣古怪,那么因?yàn)镈ockerHub鏡像在當(dāng)前的網(wǎng)絡(luò)環(huán)境下實(shí)在難以下載,不得不借助Github的Actions和阿里云的鏡像完成中轉(zhuǎn),可以利用這個(gè)開(kāi)源項(xiàng)目 進(jìn)行中轉(zhuǎn)
docker安裝
上面說(shuō)了鏡像難裝,實(shí)際上現(xiàn)在連Docker的安裝也需要費(fèi)點(diǎn)勁,我曾經(jīng)在AWS上安裝過(guò)一些Docker鏡像,那絲滑的程度真的跟教科書(shū)寫(xiě)的一模一樣,但是在我目前所處的網(wǎng)絡(luò)注定要一波三折了,CentOS7的系統(tǒng)可以按照下面的步驟操作了。
# 備份源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak # yum使用阿里云 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sudo yum makecache # 安裝必要的一些系統(tǒng)工具 sudo yum install -y wget yum-utils device-mapper-persistent-data lvm2 # 添加軟件源信息 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 修改源 sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo # 更新并安裝Docker-CE sudo yum makecache fast sudo yum -y install docker-ce # 開(kāi)啟Docker服務(wù) sudo systemctl start docker
總結(jié)
- gitlab的配置文件為 
/etc/gitlab/gitlab.rb, 發(fā)郵件需要配置smtp和email參數(shù) smtp_tls和smtp_enable_starttls_auto選項(xiàng)是互斥的,只能選擇其中一個(gè)設(shè)置為 true- 進(jìn)入到docker鏡像內(nèi)部的命令為 
docker exec -it gitlab /bin/bash 
到此這篇關(guān)于Gitlab新建用戶無(wú)法收到郵件的問(wèn)題解決辦法的文章就介紹到這了,更多相關(guān)Gitlab新建用戶無(wú)法收到郵件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
 游戲開(kāi)發(fā)進(jìn)階Unity網(wǎng)格(Mesh\動(dòng)態(tài)合批\骨骼動(dòng)畫(huà)\蒙皮)
本篇文章是進(jìn)階篇文章主要講解游戲開(kāi)發(fā)進(jìn)階,主要包含的技術(shù)有Mesh,動(dòng)態(tài)合批,骨骼動(dòng)畫(huà),蒙皮下面一起進(jìn)入U(xiǎn)nity網(wǎng)格探險(xiǎn)之旅吧2021-09-09
 Chrome瀏覽器中清除特定網(wǎng)站的Cookie數(shù)據(jù)三種方法
當(dāng)我們?cè)谑褂秒娔X瀏覽網(wǎng)頁(yè)時(shí),服務(wù)器會(huì)生成一個(gè)證書(shū)并將其返回給電腦,這個(gè)證書(shū)是cookie,也可以稱(chēng)為瀏覽器緩存,這篇文章主要給大家介紹了關(guān)于Chrome瀏覽器中清除特定網(wǎng)站的Cookie數(shù)據(jù)三種方法,需要的朋友可以參考下2023-10-10
 spark大數(shù)據(jù)任務(wù)提交參數(shù)的優(yōu)化記錄分析
這篇文章主要介紹了spark大數(shù)據(jù)任務(wù)提交參數(shù)的優(yōu)化記錄分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
 Sublime將數(shù)據(jù)json格式化的操作方法
這篇文章主要介紹了Sublime將數(shù)據(jù)json格式化的操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06
 VSCode 云同步擴(kuò)展設(shè)置Settings Sync插件
這篇文章主要介紹了VSCode 云同步擴(kuò)展設(shè)置Settings Sync插件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05

