Gitlab新建用戶無法收到郵件的問題解決辦法
前言
這個問題網(wǎng)上解決的帖子很多,根本原因就是配置錯誤,修改好配置就可以了,我也沒有其他的更加新奇的解決辦法,之所以再總結(jié)一遍只是為了自己統(tǒng)一查找方便,同時把一些差異點記錄一下,因為版本和運行環(huán)境的不同,可能跟網(wǎng)上的解決方案有一點點差異,先寫答案再聊不同吧。
解決方案
開啟企業(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測試配置是否成功
- 執(zhí)行 gitlab-rails console進入控制臺,我的機器性能較差,多等一會看到命令提示符
- 輸入后面面的命令
Notify.test_email('收件人郵箱', '郵件標(biāo)題', '正文').deliver_now
發(fā)送一封測試郵件 - 若成功過則收到測試郵件,失敗則會在控制臺顯示錯誤消息,根據(jù)錯誤信息檢查和修改配置即可
遇到的錯誤
我修改配置的旅程也不是一帆風(fēng)順的,期間也遇到的了幾個錯誤,都是在 Notify.test_email
測試之后發(fā)現(xià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
來指定自己服務(wù)器的DNS,通用的可以使用 nameserver 8.8.8.8
郵箱認證問題
/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)該填寫正確的郵箱和授權(quán)碼,同時 /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.
解決方案
這個錯誤表明在 GitLab 的配置文件中同時啟用了 smtp_tls
和 smtp_enable_starttls_auto
選項,但它們是互斥的,只能選擇其中一個設(shè)置為 true,如果使用 TLS(通常是端口 465)僅將 smtp_tls
選項設(shè)置為 true,如果使用 STARTTLS(通常是端口 587)只能將 smtp_enable_starttls_auto
設(shè)置為true。
關(guān)于gitlab的參數(shù),有一個external_url
表示gitlab的訪問域名,可以配置為 external_url 'http://gitlab.gameup.com'
,而這個域名也可以在定義容器時通過 --hostname
指定
運行環(huán)境
我的Gitlab不是在服務(wù)器上直接安裝的,而是通過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
正因為我是通過Dokcer安裝的,所以上面的很多命令需要到容器中執(zhí)行,也就是得先執(zhí)行 docker exec -it gitlab /bin/bash
而通過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
不要問我這個鏡像名字為什么這樣古怪,那么因為DockerHub鏡像在當(dāng)前的網(wǎng)絡(luò)環(huán)境下實在難以下載,不得不借助Github的Actions和阿里云的鏡像完成中轉(zhuǎn),可以利用這個開源項目 進行中轉(zhuǎn)
docker安裝
上面說了鏡像難裝,實際上現(xiàn)在連Docker的安裝也需要費點勁,我曾經(jīng)在AWS上安裝過一些Docker鏡像,那絲滑的程度真的跟教科書寫的一模一樣,但是在我目前所處的網(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 # 開啟Docker服務(wù) sudo systemctl start docker
總結(jié)
- gitlab的配置文件為
/etc/gitlab/gitlab.rb
, 發(fā)郵件需要配置smtp
和email
參數(shù) smtp_tls
和smtp_enable_starttls_auto
選項是互斥的,只能選擇其中一個設(shè)置為 true- 進入到docker鏡像內(nèi)部的命令為
docker exec -it gitlab /bin/bash
到此這篇關(guān)于Gitlab新建用戶無法收到郵件的問題解決辦法的文章就介紹到這了,更多相關(guān)Gitlab新建用戶無法收到郵件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
游戲開發(fā)進階Unity網(wǎng)格(Mesh\動態(tài)合批\骨骼動畫\蒙皮)
本篇文章是進階篇文章主要講解游戲開發(fā)進階,主要包含的技術(shù)有Mesh,動態(tài)合批,骨骼動畫,蒙皮下面一起進入Unity網(wǎng)格探險之旅吧2021-09-09Chrome瀏覽器中清除特定網(wǎng)站的Cookie數(shù)據(jù)三種方法
當(dāng)我們在使用電腦瀏覽網(wǎng)頁時,服務(wù)器會生成一個證書并將其返回給電腦,這個證書是cookie,也可以稱為瀏覽器緩存,這篇文章主要給大家介紹了關(guān)于Chrome瀏覽器中清除特定網(wǎng)站的Cookie數(shù)據(jù)三種方法,需要的朋友可以參考下2023-10-10spark大數(shù)據(jù)任務(wù)提交參數(shù)的優(yōu)化記錄分析
這篇文章主要介紹了spark大數(shù)據(jù)任務(wù)提交參數(shù)的優(yōu)化記錄分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-05-05Sublime將數(shù)據(jù)json格式化的操作方法
這篇文章主要介紹了Sublime將數(shù)據(jù)json格式化的操作方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-06-06VSCode 云同步擴展設(shè)置Settings Sync插件
這篇文章主要介紹了VSCode 云同步擴展設(shè)置Settings Sync插件,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05