Gitlab新建用户无法收到邮件的标题办理办法

[复制链接]
发表于 2025-12-29 19:31:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
媒介

这个标题网上办理的帖子很多,根本缘故原由就是设置错误,修改好设置就可以了,我也没有其他的更加新奇的办理办法,之以是再总结一遍只是为了本身同一查找方便,同时把一些差别点记录一下,由于版本和运行情况的差别,大概跟网上的办理方案有一点点差别,先写答案再聊差别吧。
  办理方案


  • 开启企业微信邮箱(QQ邮箱、163邮箱亦可)的POP3/SMTP服务,获取授权码
  • 修改gitlab的设置文件 /etc/gitlab/gitlab.rb 如下
  1. gitlab_rails['smtp_enable'] = true
  2. gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
  3. gitlab_rails['smtp_port'] = 465
  4. gitlab_rails['smtp_user_name'] = "gitlab@gameup.com"
  5. gitlab_rails['smtp_password'] = "授权码"
  6. gitlab_rails['smtp_domain'] = "exmail.qq.com"
  7. gitlab_rails['smtp_authentication'] = "login"
  8. gitlab_rails['smtp_enable_starttls_auto'] = false
  9. gitlab_rails['smtp_tls'] = true
  10. gitlab_rails['gitlab_email_enabled'] = true
  11. gitlab_rails['gitlab_email_from'] = 'gitlab@gameup.com'
  12. gitlab_rails['gitlab_email_display_name'] = 'Gitlab'
复制代码

  • 重新加载设置见效 gitlab-ctl reconfigure,等候实验完成
  • 使用gitlab测试设置是否乐成


  • 实验 gitlab-rails console进入控制台,我的呆板性能较差,多等一会看到下令提示符
  • 输入背面面的下令 Notify.test_email('收件人邮箱', '邮件标题', '正文').deliver_now 发送一封测试邮件
  • 若乐成过则收到测试邮件,失败则会在控制台体现错误消息,根据错误信息查抄和修改设置即可
遇到的错误

我修改设置的路程也不是一帆风顺的,期间也遇到的了几个错误,都是在 Notify.test_email 测试之后发现有标题,徐徐修改的
域名剖析标题

  1. Notify.test_email('shz@gamegu.com', 'Test Email', 'This is a test email from GitLab').deliver_now
  2. --------------------------------------------------------------------------------
  3. Ruby:         ruby 3.2.5 (2024-07-26 revision 31d0f1a2e7) [x86_64-linux]
  4. GitLab:       17.5.1 (e8dca573167) FOSS
  5. GitLab Shell: 14.39.0
  6. PostgreSQL:   14.11
  7. ------------------------------------------------------------[ booted in 61.07s ]
  8. Loading production environment (Rails 7.0.8.4)
  9. Delivered mail 67248a5c847e9_6f32fe445660@gitlab.gamegu.com.mail (20023.7ms)
  10. /opt/gitlab/embedded/lib/ruby/3.2.0/socket.rb:231:in getaddrinfo': getaddrinfo: Temporary failure in name resolution (SocketError)
  11.         from /opt/gitlab/embedded/lib/ruby/3.2.0/socket.rb:231:in foreach'
  12.         from /opt/gitlab/embedded/lib/ruby/3.2.0/socket.rb:635:in tcp'
  13.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:643:in tcp_socket'
  14.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:656:in do_start'
  15.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:611:in start'
  16.         from /opt/gitlab/embedded/service/gitlab-rails/config/initializers/mail_starttls_patch.rb:53:in start_smtp_session'
  17.         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!'
  18.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:2145:in do_delivery'
  19.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in block in deliver'
  20.         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'
  21.         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'
  22.         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'
  23.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications.rb:206:in instrument'
  24.         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'
  25.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in deliver'
  26.         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'
  27.         ... 15 levels...
  28. irb(main):002:0>
复制代码
办理办法

修改 /etc/resolv.conf 来指定本身服务器的DNS,通用的可以使用 nameserver 8.8.8.8
邮箱认证标题

  1. /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)
  2.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:1044:in getok'
  3.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:945:in mailfrom'
  4.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:767:in send_message'
  5.         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!'
  6.         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!'
  7.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:612:in start'
  8.         from /opt/gitlab/embedded/service/gitlab-rails/config/initializers/mail_starttls_patch.rb:53:in start_smtp_session'
  9.         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!'
  10.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:2145:in do_delivery'
  11.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in block in deliver'
  12.         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'
  13.         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'
  14.         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'
  15.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/notifications.rb:206:in instrument'
  16.         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'
  17.         from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/message.rb:253:in deliver'
  18.         ... 16 levels...
复制代码
办理方案

smtp 设置中应该填写精确的邮箱和授权码,同时 /etc/gitlab/gitlab.rb 中设置 gitlab_rails['gitlab_email_from'] 与 gitlab_rails['smtp_user_name'] 划一
端口设置互斥

  1. 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 选项,但它们是互斥的,只能选择此中一个设置为 true,假如使用 TLS(通常是端口 465)仅将 smtp_tls 选项设置为 true,假如使用 STARTTLS(通常是端口 587)只能将 smtp_enable_starttls_auto 设置为true。
关于gitlab的参数,有一个external_url 体现gitlab的访问域名,可以设置为 external_url 'http://gitlab.gameup.com',而这个域名也可以在界说容器时通过 --hostname 指定
运行情况

我的Gitlab不是在服务器上直接安装的,而是通过Docker安装的gitlab镜像,服务器是CentOS7体系,gitlab组件干系版本如下:
   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安装的,以是上面的很多下令须要到容器中实验,也就是得先实验 docker exec -it gitlab /bin/bash
而通过Docker安装gitlab的下令也枚举一下:
  1. docker run --detach \
  2.   --hostname gitlab.gameup.com \
  3.   --publish 443:443 --publish 80:80 --publish 22:22 \
  4.   --name gitlab \
  5.   --restart always \
  6.   --volume /export/docker/gitlab/config:/etc/gitlab \
  7.   --volume /export/docker/gitlab/logs:/var/log/gitlab \
  8.   --volume /export/docker/gitlab/data:/var/opt/gitlab \
  9.   registry.cn-hangzhou.aliyuncs.com/z5z/gitlab-ce:latest
复制代码
不要问我这个镜像名字为什么如许古怪,那么由于DockerHub镜像在当前的网络情况下着实难以下载,不得不借助Github的Actions和阿里云的镜像完成中转,可以使用这个开源项目 举行中转
docker安装

上面说了镜像难装,现实上现在连Docker的安装也须要费点劲,我曾经在AWS上安装过一些Docker镜像,那丝滑的程度真的跟教科誊写的千篇一律,但是在我现在所处的网络注定要一波三折了,CentOS7的体系可以按照下面的步调操纵了。
  1. # 备份
  2. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  3. # yum使用阿里云
  4. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  5. sudo yum makecache
  6. # 安装必要的一些系统工具
  7. sudo yum install -y wget yum-utils device-mapper-persistent-data lvm2
  8. # 添加软件源信息
  9. sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  10. # 修改源
  11. sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
  12. # 更新并安装Docker-CE
  13. sudo yum makecache fast
  14. sudo yum -y install docker-ce
  15. # 开启Docker服务
  16. sudo systemctl start docker
复制代码
总结



  • gitlab的设置文件为 /etc/gitlab/gitlab.rb, 发邮件须要设置 smtp 和 email 参数
  • smtp_tls 和 smtp_enable_starttls_auto 选项是互斥的,只能选择此中一个设置为 true
  • 进入到docker镜像内部的下令为 docker exec -it gitlab /bin/bash

   ==>> 反爬链接,请勿点击,原地爆炸,概不负责!<<==  
   他时若遂凌云志,敢笑黄巢不丈夫。伟人可以被人们敬仰,也可以被用来作为登天的蹊径,借他人之成绩,抒发本身之情怀~

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表