{"id":3398,"date":"2019-06-22T22:27:42","date_gmt":"2019-06-22T19:27:42","guid":{"rendered":"https:\/\/kifarunix.com\/?p=3398"},"modified":"2024-03-11T23:06:27","modified_gmt":"2024-03-11T20:06:27","slug":"configure-sendmail-to-use-gmail-relay-on-ubuntu-18-04-debian-10-9","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/configure-sendmail-to-use-gmail-relay-on-ubuntu-18-04-debian-10-9\/","title":{"rendered":"Configure Sendmail to Use Gmail Relay on Ubuntu|Debian"},"content":{"rendered":"\n<p>In this guide, we are going to learn how to configure <a aria-label=\"Sendmail (opens in a new tab)\" href=\"ftp:\/\/ftp.iitb.ac.in\/LDP\/en\/solrhe\/chap22sec173.html\" target=\"_blank\" rel=\"noreferrer noopener\">Sendmail<\/a> to use Gmail Relay on Ubuntu 18.04\/Debian 10\/9. <a aria-label=\"Sendmail (opens in a new tab)\" href=\"https:\/\/linux.die.net\/man\/8\/sendmail.sendmail\" target=\"_blank\" rel=\"noreferrer noopener\">Sendmail<\/a> can be configured to relay mails via external mail servers including Gmail SMTP.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#configuring-sendmail-to-use-gmail-relay-on-ubuntu-debian\">Configuring Sendmail to Use Gmail Relay on Ubuntu\/Debian<\/a><ul><li><a href=\"#install-sendmail-on-ubuntu-18-04-debian-10-9\">Install Sendmail on Ubuntu 18.04\/Debian 10\/9<\/a><\/li><li><a href=\"#define-gmail-authentication-details\">Define Gmail Authentication Details<\/a><\/li><li><a href=\"#create-sendmail-gmail-authentication-database-map\">Create Sendmail-Gmail Authentication Database Map<\/a><\/li><li><a href=\"#configure-sendmail-smart-host\">Configure Sendmail Smart Host<\/a><\/li><li><a href=\"#regenerate-sendmail-configuration\">Regenerate Sendmail Configuration<\/a><\/li><li><a href=\"#reload-sendmail\">Reload Sendmail<\/a><\/li><li><a href=\"#testing-sendmail-gmail-relay\">Testing Sendmail Gmail Relay<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"configuring-sendmail-to-use-gmail-relay-on-ubuntu-debian\">Configuring Sendmail to Use Gmail Relay on Ubuntu\/Debian<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-sendmail-on-ubuntu-18-04-debian-10-9\">Install Sendmail on Ubuntu 18.04\/Debian 10\/9<\/h3>\n\n\n\n<p>Before you can install Sendmail, ensure that you remove other existing MTAs such as Postfix.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt --purge autoremove postfix<\/pre>\n\n\n\n<p>Next, install Sendmail and other mail utilities if not installed already.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt install sendmail sendmail-bin mailutils libsasl2-modules openssl<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"define-gmail-authentication-details\">Define Gmail Authentication Details<\/h3>\n\n\n\n<p>Next, you need to create a directory to store a file that defines how to connect to Gmail SMTP server for mail relay. Hence, create a directory as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir -m 700 \/etc\/mail\/authinfo<\/code><\/pre>\n\n\n\n<p>Next, create a file to store Gmail authentication details under the directory created above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/mail\/authinfo\/gmail-smtp-auth<\/code><\/pre>\n\n\n\n<p>The file should define Gmail authentication information should contain the line below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>AuthInfo: \"U:root\" \"I:USER@gmail.com\" \"P:GMAIL_USER_PASSWORD\"<\/code><\/pre>\n\n\n\n<p>Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>U<\/strong> <strong>(The user (authorization) identifier)<\/strong>: defines the name of the user that sendmail will use to check allowable permissions.<\/li>\n\n\n\n<li><strong>I (The authentication Identifier)<\/strong>: Name of the user allowed to setup a connection.<\/li>\n\n\n\n<li>P: The clear text for  the authentication user used to authorize the mail connections.<\/li>\n<\/ul>\n\n\n\n<p>Replace <strong>USER<\/strong> <strong>ID<\/strong> and <strong>GMAIL_USER_PASSWORD<\/strong> with your Gmail account user ID and password respectively.<\/p>\n\n\n\n<p>NOTE that the use of less secure app access has been deprecated. See how you can use App password as an alternative in the guide below;<\/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<h3 class=\"wp-block-heading\" id=\"create-sendmail-gmail-authentication-database-map\">Create Sendmail-Gmail Authentication Database Map<\/h3>\n\n\n\n<p>Next, you need to generate the Sendmail gmail authentication databas map from the above authentication information. You can use the <strong>makemap<\/strong> utility as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>makemap hash \/etc\/mail\/authinfo\/gmail-smtp-auth &lt; \/etc\/mail\/authinfo\/gmail-smtp-auth<\/code><\/pre>\n\n\n\n<p>This will create authentication database, <strong>\/etc\/mail\/authinfo\/gmail-smtp-auth.db<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-sendmail-smart-host\">Configure Sendmail Smart Host<\/h3>\n\n\n\n<p>A smart host\/smarthost is used to specify an SMTP server that relays emails, in this case, <strong>smtp.gmail.com<\/strong>. This can be defined using <strong>SMART_HOST<\/strong>&nbsp;macro.<\/p>\n\n\n\n<p>The definition should made in <strong>\/etc\/mail\/sendmail.mc<\/strong> configuration file <strong>JUST BEFORE<\/strong> the <strong>MAILER<\/strong> definition. If you need to create a comment, begin a line with <strong>dnl<\/strong>.<\/p>\n\n\n\n<p>Note the line;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>FEATURE(<code>authinfo',<\/code>hash -o <strong>\/etc\/mail\/authinfo\/gmail-smtp-auth.db<\/strong>')dnl<\/code><\/pre>\n\n\n\n<p>Replace it with your Gmail Authentication sendmail database map you generated above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/mail\/sendmail.mc<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\ndnl #\ndnl # Defining Gmail Smarthost for sendmail\ndefine(`SMART_HOST',`[smtp.gmail.com]')dnl\ndefine(`RELAY_MAILER_ARGS', `TCP $h 587')dnl\ndefine(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl\ndefine(`confAUTH_OPTIONS', `A p')dnl\nTRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl\ndefine(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl\nFEATURE(`authinfo',`hash -o \/etc\/mail\/authinfo\/gmail-smtp-auth.db')dnl\ndnl #\ndnl # Default Mailer setup\nMAILER_DEFINITIONS\nMAILER(`local')dnl\nMAILER(`smtp')dnl\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"regenerate-sendmail-configuration\">Regenerate Sendmail Configuration<\/h3>\n\n\n\n<p>Save the configuration file above and re-build Sendmail configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make -C \/etc\/mail<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\nCreating \/etc\/mail\/relay-domains\n# Optional file...\nUpdating Makefile ...\nReading configuration from \/etc\/mail\/sendmail.conf.\nValidating configuration.\nCreating \/etc\/mail\/Makefile...\nUpdating sendmail.cf ...\nThe following file(s) have changed:\n  \/etc\/mail\/relay-domains \/etc\/mail\/sendmail.cf\n** ** You should issue `\/etc\/init.d\/sendmail reload` ** **\nmake: Leaving directory '\/etc\/mail'\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"reload-sendmail\">Reload Sendmail<\/h3>\n\n\n\n<p>After rebuilding Sendmail configuration, reload Sendmail.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/etc\/init.d\/sendmail reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"testing-sendmail-gmail-relay\">Testing Sendmail Gmail Relay<\/h3>\n\n\n\n<p>To verify that the setup actually works, try to send a test mail using sendmail. For example;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"This is a test for sendmail gmail relay\" | sendmail test-user@gmail.com<\/code><\/pre>\n\n\n\n<p>You should be able to receive a mail with a body, <strong>This is a test for sendmail gmail relay<\/strong>. Also check the mail logs.<\/p>\n\n\n\n<p>That is all on how to configure Sendmail to use Gmail relay on Ubuntu\/Debian.<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-zimbra-mail-server-on-fedora30-29-centos-7\/\" target=\"_blank\">Install Zimbra Mail Server on Fedora 30\/29\/CentOS 7<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/encrypt-emails-using-enigmail-on-thunderbird\/\" target=\"_blank\">Encrypt Emails using Enigmail on Thunderbird<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/configure-postfix-to-use-gmail-smtp-on-ubuntu-18-04\/\" target=\"_blank\">Configure Postfix to Use Gmail SMTP on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-install-and-setup-roundcube-webmail-on-debain-9\/\" target=\"_blank\">How to Install and Setup Roundcube Webmail on Debian 9<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-setup-iredmail-mail-server-on-ubuntu-18-04-lts\/\" target=\"_blank\">How to Install and Setup iRedMail Mail Server on Ubuntu 18.04 LTS<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-install-and-setup-thunderbird-mail-client-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to Install and Setup Thunderbird Mail Client on Ubuntu 18.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to learn how to configure Sendmail to use Gmail Relay on Ubuntu 18.04\/Debian 10\/9. Sendmail can be configured to<\/p>\n","protected":false},"author":1,"featured_media":13784,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,272,1006],"tags":[5712,997,287,1008,1007,1009,67],"class_list":["post-3398","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-email","category-sendmail","tag-configure-sendmail-to-use-gmail-relay","tag-debian-10","tag-debian-9","tag-gmail-relay","tag-sendmail","tag-smarthost","tag-ubuntu-18-04","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\/3398"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=3398"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3398\/revisions"}],"predecessor-version":[{"id":21161,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3398\/revisions\/21161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/13784"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=3398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=3398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=3398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}