{"id":10665,"date":"2021-10-14T23:55:03","date_gmt":"2021-10-14T20:55:03","guid":{"rendered":"https:\/\/kifarunix.com\/?p=10665"},"modified":"2024-03-18T13:42:48","modified_gmt":"2024-03-18T10:42:48","slug":"configure-gitlab-to-use-gmail-smtp-for-outbound-mails","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/configure-gitlab-to-use-gmail-smtp-for-outbound-mails\/","title":{"rendered":"Configure Gitlab to use Gmail SMTP for Outbound Mails"},"content":{"rendered":"\n
This tutorial will describe how to configure Gitlab to use Gmail SMTP for Outbound mails. In our previous tutorials, we learnt how to install and setup Gitlab CE.<\/p>\n\n\n\n
Install Gitlab CE on Debian 11<\/a><\/p>\n\n\n\n Install Gitlab with SSL\/TLS Certificate on Ubuntu 20.04<\/a><\/p>\n\n\n\n Gitlab can be configured to use Sendmail or Postfix to relay emails. However, if you want to configure it to sent emails through Gmail SMTP, proceed as follows.<\/p>\n\n\n\n Open the Gitlab configuration file for editing;<\/p>\n\n\n\n Navigate to Such that they look like as shown below.<\/p>\n\n\n\n Ensure that you replace the Similarly, replace the value Save and exit the configuration file once done editing.<\/p>\n\n\n\n If instead of setting the credentials in plain text as defined by the lines below, as shown above;<\/p>\n\n\n\n You can encrypt them for security purposes.<\/p>\n\n\n\n To encrypt Gitlab Gmail SMTP credentials;<\/p>\n\n\n\n The command opens a file. Uncomment the lines and set the correct values for the username and password.<\/p>\n\n\n\n Save and exit the file.<\/p>\n\n\n\n The encrypted configurations are stored in the file, Next, remove these lines;<\/p>\n\n\n\n from the configuration file, if you already configured them by running the command below;<\/p>\n\n\n\n Next, reconfigure Gitlab application;<\/p>\n\n\n\n Ensure that you configure Gmail account well;<\/p>\n\n\n\nConfiguring Gitlab to use Gmail SMTP for Outbound Mails<\/h2>\n\n\n\n
Configure Gitlab Gmail Server Settings<\/h3>\n\n\n\n
vim \/etc\/gitlab\/gitlab.rb<\/code><\/pre>\n\n\n\n
### Gitlab email server settings section<\/code><\/strong>, uncomment (by removing hashe, # at the beginning of the lines) and update appropriate values in the lines below;<\/p>\n\n\n\n
\n# gitlab_rails['smtp_enable'] = true\n# gitlab_rails['smtp_address'] = \"smtp.server\"\n# gitlab_rails['smtp_port'] = 465\n# gitlab_rails['smtp_user_name'] = \"smtp user\"\n# gitlab_rails['smtp_password'] = \"smtp password\"\n# gitlab_rails['smtp_domain'] = \"example.com\"\n# gitlab_rails['smtp_authentication'] = \"login\"\n# gitlab_rails['smtp_enable_starttls_auto'] = true\n# gitlab_rails['smtp_tls'] = false\n# gitlab_rails['smtp_pool'] = false\n...\n# gitlab_rails['smtp_openssl_verify_mode'] = 'none'\n<\/code><\/pre>\n\n\n\n
email-id@gmail.com<\/code><\/strong> with your correct Gmail ID like,
gitlab@gmail.com<\/code><\/strong>.<\/p>\n\n\n\n
email-id-password<\/code><\/strong> with your Gmail account password.<\/p>\n\n\n\n
\ngitlab_rails['smtp_enable'] = true\ngitlab_rails['smtp_address'] = \"smtp.gmail.com\"\ngitlab_rails['smtp_port'] = 587\ngitlab_rails['smtp_user_name'] = \"email-id@gmail.com\"\ngitlab_rails['smtp_password'] = \"email-id-password\"\ngitlab_rails['smtp_domain'] = \"smtp.gmail.com\"\ngitlab_rails['smtp_authentication'] = \"login\"\ngitlab_rails['smtp_enable_starttls_auto'] = true\ngitlab_rails['smtp_tls'] = false<\/strong>\n# gitlab_rails['smtp_pool'] = false\n...\ngitlab_rails['smtp_openssl_verify_mode'] = 'peer'<\/strong>\n<\/code><\/pre>\n\n\n\n
Encrypting Gitlab Gmail SMTP Credentials<\/h3>\n\n\n\n
gitlab_rails['smtp_user_name'] = \"email-id@gmail.com\"\ngitlab_rails['smtp_password'] = \"email-id-password\"<\/code><\/pre>\n\n\n\n
\n
gitlab-rake gitlab:smtp:secret:edit EDITOR=vim<\/code><\/pre>\n\n\n\n
password: 'email-id-password<\/strong>'\nuser_name: 'email-id@gmail.com<\/strong>'<\/code><\/pre>\n\n\n\n
\/var\/opt\/gitlab\/gitlab-rails\/shared\/encrypted_settings\/smtp.yaml.enc<\/code><\/strong>.<\/p>\n\n\n\n
gitlab_rails['smtp_user_name'] = \"email-id@gmail.com\"\ngitlab_rails['smtp_password'] = \"email-id-password\"<\/code><\/pre>\n\n\n\n
sed -i -r '\/smtp_user_name|smtp_password\/d' \/etc\/gitlab\/gitlab.rb<\/code><\/pre>\n\n\n\n
Reconfigure Gitlab Application<\/h3>\n\n\n\n
gitlab-ctl reconfigure<\/code><\/pre>\n\n\n\n
Allow Gmail Account Less Secure App Access<\/h3>\n\n\n\n