{"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<p>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<p><a href=\"https:\/\/kifarunix.com\/install-gitlab-ce-on-debian-11\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Gitlab CE on Debian 11<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-gitlab-with-ssl-tls-certificate-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Gitlab with SSL\/TLS Certificate on Ubuntu 20.04<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring Gitlab to use Gmail SMTP for Outbound Mails<\/h2>\n\n\n\n<p>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<h3 class=\"wp-block-heading\">Configure Gitlab Gmail Server Settings<\/h3>\n\n\n\n<p>Open the Gitlab configuration file for editing;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/gitlab\/gitlab.rb<\/code><\/pre>\n\n\n\n<p>Navigate to <strong><code>### 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<pre class=\"scroll-box\"><code>\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<p>Such that they look like as shown below.<\/p>\n\n\n\n<p>Ensure that you replace the <strong><code>email-id@gmail.com<\/code><\/strong> with your correct Gmail ID like, <strong><code>gitlab@gmail.com<\/code><\/strong>.<\/p>\n\n\n\n<p>Similarly, replace the value <strong><code>email-id-password<\/code><\/strong> with your Gmail account password.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n<strong>gitlab_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...\n<strong>gitlab_rails['smtp_openssl_verify_mode'] = 'peer'<\/strong>\n<\/code><\/pre>\n\n\n\n<p>Save and exit the configuration file once done editing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Encrypting Gitlab Gmail SMTP Credentials<\/h3>\n\n\n\n<p>If instead of setting the credentials in plain text as defined by the lines below, as shown above;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gitlab_rails&#91;'smtp_user_name'] = \"email-id@gmail.com\"\ngitlab_rails&#91;'smtp_password'] = \"email-id-password\"<\/code><\/pre>\n\n\n\n<p>You can encrypt them for security purposes.<\/p>\n\n\n\n<p>To encrypt Gitlab Gmail SMTP credentials;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update the username and password in the encrypted YAML file by running the command below. You can use your preferred editor instead of VIM in the command below;<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>gitlab-rake gitlab:smtp:secret:edit EDITOR=vim<\/code><\/pre>\n\n\n\n<p>The command opens a file. Uncomment the lines and set the correct values for the username and password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>password: '<strong>email-id-password<\/strong>'\nuser_name: '<strong>email-id@gmail.com<\/strong>'<\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>The encrypted configurations are stored in the file, <strong><code>\/var\/opt\/gitlab\/gitlab-rails\/shared\/encrypted_settings\/smtp.yaml.enc<\/code><\/strong>.<\/p>\n\n\n\n<p>Next, remove these lines;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gitlab_rails&#91;'smtp_user_name'] = \"email-id@gmail.com\"\ngitlab_rails&#91;'smtp_password'] = \"email-id-password\"<\/code><\/pre>\n\n\n\n<p>from the configuration file, if you already configured them by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sed -i -r '\/smtp_user_name|smtp_password\/d' \/etc\/gitlab\/gitlab.rb<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Reconfigure Gitlab Application<\/h3>\n\n\n\n<p>Next, reconfigure Gitlab application;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gitlab-ctl reconfigure<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Allow Gmail Account Less Secure App Access<\/h3>\n\n\n\n<p>Ensure that you configure Gmail account well;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-postfix-to-use-gmail-app-passwords\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure Postfix to Use Gmail App Passwords<\/a><\/p>\n\n\n\n<p>You should now be able to receive emails from Gitlab.<\/p>\n\n\n\n<p>For example, update the administrator&#8217;s email, log out and attempt to reset the password.<\/p>\n\n\n\n<p>You will be prompted to enter the administrator&#8217;s email address to which the reset details will be sent to.<\/p>\n\n\n\n<p>Sample Password reset email.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1416\" height=\"542\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/sample-password-reset-email.png\" alt=\"\" class=\"wp-image-10671\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/sample-password-reset-email.png?v=1634244750 1416w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/sample-password-reset-email-768x294.png?v=1634244750 768w\" sizes=\"(max-width: 1416px) 100vw, 1416px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Reference<\/h3>\n\n\n\n<p><a href=\"https:\/\/docs.gitlab.com\/omnibus\/settings\/smtp.html\" target=\"_blank\" rel=\"noreferrer noopener\">Gitlab SMTP Settings<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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<\/p>\n","protected":false},"author":3,"featured_media":10672,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121],"tags":[4187,2916,4188,4189,4190],"class_list":["post-10665","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-configure-gitlab-to-use-gmail-smtp-for-outbound-mails","tag-gitlab","tag-gitlab-gmail-settings","tag-gitlab-smtp","tag-gmail-smtp-settings","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10665"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=10665"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10665\/revisions"}],"predecessor-version":[{"id":21638,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10665\/revisions\/21638"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10672"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=10665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=10665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=10665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}