Hoppa till innehållet

Apps

GitLab

Send the mail that a self-managed GitLab writes, such as notifications, password resets and failed pipelines, through Sendora’s SMTP. GitLab.com sends its own mail, so this guide is for a GitLab that you run yourself, from the Linux package or its Docker image.

Before you start

  • A Sendora account. A test server works from the moment the account exists. A live server sends once your account is approved. The account starts on Free, within the limits that Account › Usage in the dashboard shows.
  • Access to the DNS of the domain that GitLab’s mail comes from.
  • Root access to the machine or the container that runs GitLab.

Set up GitLab

  1. Add the domain that GitLab’s mail comes from under Domains, and add the two DNS records it shows, as Domains explains.
  2. Create a test server under Servers › New server, with Testserver ticked, and create a key on its API keys tab. The key starts with sk_test_. A test server takes mail as a live server does and delivers none of it.
  3. Add these lines to /etc/gitlab/gitlab.rb, with the server key as both user name and password:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.sendora.se"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "sk_test_…"
gitlab_rails['smtp_password'] = "sk_test_…"
gitlab_rails['smtp_domain'] = "gitlab.example.se"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
gitlab_rails['gitlab_email_from'] = 'gitlab@example.se'
gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.se'

Put an address on your verified domain in gitlab_email_from, since GitLab otherwise sends from gitlab@ its own host name. smtp_domain is the name GitLab gives when it connects, such as its own host name. With smtp_openssl_verify_mode set to peer, GitLab checks Sendora’s certificate and its name.

Port 465 encrypts the connection from the first byte. Port 587 works too, with smtp_tls set to false and smtp_enable_starttls_auto set to true. GitLab then starts TLS only if the server offers it. Lines 678 to 686 of Ruby’s SMTP library, which GitLab 19.6.2 uses, show this. If someone between GitLab and Sendora removed that offer, GitLab would send the key unencrypted, so use 465 where you can. If GitLab runs on a host that blocks ports 465 and 587, such as a DigitalOcean Droplet, use port 2525 as you would 587.

  1. Run sudo gitlab-ctl reconfigure, which applies the new settings.
  2. Send a test message from GitLab’s Rails console. Run sudo gitlab-rails console, and at its prompt run:
Notify.test_email('you@example.se', 'Sendora test', 'It works.').deliver_now
  1. Find the message on the server’s Messages tab under Servers.
  2. Once your account is approved, create a key on your live server’s API keys tab, such as the default server that signup made. Put it in smtp_user_name and smtp_password in place of the test key, and run sudo gitlab-ctl reconfigure again.

GitLab in Docker

GitLab’s Docker image keeps gitlab.rb in the volume it mounts at /etc/gitlab. Edit the file there, and run each command in the container, such as docker exec -it gitlab gitlab-ctl reconfigure for a container named gitlab. If you configure the container through GITLAB_OMNIBUS_CONFIG instead, add the same lines there and recreate the container.

If a message is refused

GitLab sends most of its mail in the background, through Sidekiq. When Sendora refuses a message, Sidekiq’s log at /var/log/gitlab/sidekiq/current holds the error with Sendora’s reply. In the Rails console, deliver_now raises the same error. 535 5.7.8 means the key is wrong or revoked. 550 5.7.1 means the From domain is not verified, or that a live server’s account is not yet approved. 451 4.7.0 means that a limit is reached, such as Free’s daily limit. 550 5.1.1 means the recipient’s address is on the suppression list, for example after a hard bounce. SMTP replies lists every reply.

Test the setup

On the server’s API keys tab under Servers, Test the setup shows each valid key’s latest sign-in and accepted message over SMTP. It also shows the key’s latest refusals, each with what to do. After GitLab sends a message, click Check now.