Gitlab emails for community edition

Hello all,

My company is using the GitLab Community Edition and I have the task of setting up SMTP to send emails from GitLab. I have tried several configuration methods, and ways but nothing seems to work.

Is sending emails supported for the GitLab community edition?

Thanks,

What version do you use? Latest is 12.3

Hi.

Running an older version 8.5.10.
I’m thinking that does not matter since the reconfiguration shows the updated mail settings.

I am mostly asking if the community edition supports emailing.

Thanks

Hi @aeubank!

The solution to your problem is two fold. Firstly you have to set up your SMTP server. And secondly, you will need to integrate the SMTP server with the GitLab server. I have used Postfix as SMTP server. Please find below, the steps to setup the same:

Steps to set up Postfix server: (run all the below steps as ‘root’ user, until otherwise mentioned)

  1. Install telnet, telnet-server and postfix on your server(say 192.168.2.2)
  2. Make sure the firewall is disabled and selinux is permissive or disabled
  3. start and enable the services (telnet.socket and postfix)
  4. From the '/etc/hosts’ file, map the IPAddress to a domain name

192.168.2.2 example.com

  1. Edit the file ‘/etc/postfix/main.cf’ as below

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = example.com
mynetworks = 127.0.0.0/8
relay_domains = $mydestination
home_mailbox = Maildir/
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

  1. Make sure that you insert the same values in the attributes ‘mydomain’ and ‘myhostname’
  2. Restart the postfix service and then run the following command:

echo “Hi! This is a test mail. Please do not reply” | mail -s “Testing Mail” root@example.com

  1. Now, goto the directory you have configured for mails under the “home_mailbox” attribute in ‘/etc/postfix/main.cf’ file(in this case the value is “Maildir/”)

cd ~/Maildir/

  1. Check for a file under the “new” sub-directory(~/Maildir/new/). If you have received a mail then, the Postfix is setup correctly. You should now, move to the next section, integrating Postfix with GitLab.

Steps to Integrate Postfix with GitLab:

  1. From the GitLab server, open the GitLab configuration file ‘/etc/gitlab/gitlab.rb’ and edit the file as below:

external_url ‘http://gitlab-example.com:3000
gitlab_rails[‘smtp_enable’] = true
gitlab_rails[‘smtp_address’] = ‘example.com
gitlab_rails[‘smtp_port’] = 25
gitlab_rails[‘smtp_domain’] = ‘example.com
gitlab_rails[‘smtp_tls’] = false
gitlab_rails[‘smtp_openssl_verify_mode’] = ‘none’
gitlab_rails[‘smtp_enable_starttls_auto’] = false
gitlab_rails[‘smtp_ssl’] = false
gitlab_rails[‘smtp_force_ssl’] = false

  1. Now, reconfigure the GitLab server

gitlab-ctl reconfigure

  1. Open the ‘/etc/hosts’ file and map the IPAddresses with the domain names:

192.168.1.1(IP-address-of-gitlab) gitlab-example.com
192.168.2.2(IP-address-of-postfix-server) example.com

  1. Open the gitlab-rails console by running the following command on the Gitlab server:

gitlab-rails console

  1. From the gitlab-rails console run the following command to check if the Postfix server is integrated with the GitLab successfully

Notify.test_email(‘root@example.com’, ‘This is a test mail via gitlab’, ‘This is a sample test body.’).deliver_now

  1. After running the above command, exit from the gitlab-rails console and check the directory on the postfix server that you have configured for mails under the “home_mailbox” attribute in ‘/etc/postfix/main.cf’ file(in this case the value is “Maildir/”)