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?
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)
Install telnet, telnet-server and postfix on your server(say 192.168.2.2)
Make sure the firewall is disabled and selinux is permissive or disabled
start and enable the services (telnet.socket and postfix)
From the '/etc/hosts’ file, map the IPAddress to a domain name
Make sure that you insert the same values in the attributes ‘mydomain’ and ‘myhostname’
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
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/
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:
From the GitLab server, open the GitLab configuration file ‘/etc/gitlab/gitlab.rb’ and edit the file as below:
Open the gitlab-rails console by running the following command on the Gitlab server:
gitlab-rails console
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
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/”)