Preface
There are many posts to solve this problem online. The fundamental reason is configuration errors. Just modify the configuration. I don’t have any other more novel solutions. The reason I summarized it again is just for the convenience of finding it myself. At the same time, I recorded some differences. Because of the difference between the version and the operating environment, there may be a little difference from the online solution. Write the answer first and then talk about the difference.
Solution
Open the POP3/SMTP service of the enterprise WeChat email (QQ email, 163 email is also available) and obtain the authorization code
Modify gitlab configuration file
/etc/gitlab/
as follows
gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "gitlab@" gitlab_rails['smtp_password'] = "Authorization Code" gitlab_rails['smtp_domain'] = "" 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@' gitlab_rails['gitlab_email_display_name'] = 'Gitlab'
Reload configuration takes effect
gitlab-ctl reconfigure
, waiting for execution to completeUse gitlab to test whether the configuration is successful
- Execute gitlab-rails console to enter the console. My machine has poor performance. I will wait for a while and see the command prompt.
- Enter the commands below
Notify.test_email('Recipient Email', 'Email Title', 'Text').deliver_now
Send a test email - If you pass successfully, you will receive a test email. If you fail, an error message will be displayed on the console. You can check and modify the configuration based on the error message.
Error encountered
My journey of modifying the configuration was not smooth, and I encountered several errors during this period, all of which wereNotify.test_email
After the test, I found any problems and gradually modified them
Domain name resolution problem
Notify.test_email('shz@', '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@ (20023.7ms) /opt/gitlab/embedded/lib/ruby/3.2.0/:231:in getaddrinfo': getaddrinfo: Temporary failure in name resolution (SocketError) from /opt/gitlab/embedded/lib/ruby/3.2.0/:231:in foreach' from /opt/gitlab/embedded/lib/ruby/3.2.0/:635:in tcp' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/:643:in tcp_socket' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/:656:in do_start' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/: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/:100:in deliver!' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/:2145:in do_delivery' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/:253:in block in deliver' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/: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/: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/:24:in instrument' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/:206:in instrument' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/:586:in deliver_mail' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/: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>
Solution
Revise/etc/
To specify the DNS of your own server, you can use it for general purposenameserver 8.8.8.8
Email authentication issues
/opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/: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/:1044:in getok' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/:945:in mailfrom' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/: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/:101:in block in deliver!' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/net-smtp-0.3.3/lib/net/: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/:100:in deliver!' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/:2145:in do_delivery' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/:253:in block in deliver' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/: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/: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/:24:in instrument' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/:206:in instrument' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/actionmailer-7.0.8.4/lib/action_mailer/:586:in deliver_mail' from /opt/gitlab/embedded/lib/ruby/gems/3.2.0/gems/mail-2.8.1/lib/mail/:253:in deliver' ... 16 levels...
Solution
smtp
The correct email and authorization code should be filled in the configuration, and at the same time/etc/gitlab/
Settingsgitlab_rails['gitlab_email_from']
andgitlab_rails['smtp_user_name']
Consistent
Port configuration mutually exclusive
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.
Solution
This error indicates that it is enabled in the GitLab configuration file.smtp_tls
andsmtp_enable_starttls_auto
Options, but they are mutually exclusive, only one of them can be selected to set to true, if using TLS (usually port 465) onlysmtp_tls
Option is set to true, if you use STARTTLS (usually port 587), you can onlysmtp_enable_starttls_auto
Set to true.
Regarding gitlab parameters, there is aexternal_url
Indicates the access domain name of gitlab, which can be configured asexternal_url ''
, and this domain name can also be passed when defining the container--hostname
Specify
Running environment
My Gitlab is not installed directly on the server, but a gitlab image installed through Docker. The server is a CentOS7 system. The related version of the gitlab component is as follows:
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
Because I installed it through Dokcer, many of the above commands need to be executed in the container, that is, I have to execute it first.docker exec -it gitlab /bin/bash
The command to install gitlab through Docker is also listed:
docker run --detach \ --hostname \ --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 \ /z5z/gitlab-ce:latest
Don't ask me why this image name is so weird. Because the DockerHub image is really difficult to download in the current network environment, I have to use Github Actions and Alibaba Cloud image to complete the transfer. You can use thisOpen Source ProjectContinue to transfer
docker installation
The above said that mirrors are difficult to install. In fact, even Docker installation now requires some effort. I have installed some Docker images on AWS, and the silkyness is really exactly the same as the textbooks. However, the network I am currently in is destined to be full of twists and turns. The CentOS7 system can follow the steps below.
# Backup sourcemv /etc// /etc// # yum uses Alibaba Cloudcurl -o /etc// /repo/ sudo yum makecache # Install some necessary system toolssudo yum install -y wget yum-utils device-mapper-persistent-data lvm2 # Add software source informationsudo yum-config-manager --add-repo /docker-ce/linux/centos/ # Modify the sourcesudo sed -i 's++/docker-ce+' /etc// # Update and install Docker-CEsudo yum makecache fast sudo yum -y install docker-ce # Enable Docker servicesudo systemctl start docker
Summarize
- gitlab's configuration file is
/etc/gitlab/
, mailing requires configurationsmtp
andemail
Parameters -
smtp_tls
andsmtp_enable_starttls_auto
The options are mutually exclusive, and only one of them can be selected to set to true - The command to enter the docker image is
docker exec -it gitlab /bin/bash
This is the article about the problem of Gitlab’s new user not receiving emails. This is all about this article. For more related Gitlab’s new user not receiving emails, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!