Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Mail Servers»Sendmail»Configure Sendmail to Relay Emails through Gmail SMTP

    Configure Sendmail to Relay Emails through Gmail SMTP

    By RahulFebruary 18, 20192 Mins Read

    Sendmail provides the option to send emails via the external SMTP servers. This tutorial will help you to configure Sendmail to relay email through external SMTP servers like Gmail, Amazon SES, Mailchimp, Mandrill etc. In this tutorial, we are using the Gmail SMTP server to relay emails from Sendmail server.

    Advertisement

    1. Create Auth File

    First create directory for storing authentication files.

    sudo mkdir /etc/mail/authinfo
    sudo chmod 700 /etc/mail/authinfo
    

    Now, create an auth file with any name like smtp-auth and add the following content. Replace the above email with your gmail or google apps email.

    sudo vi /etc/mail/authinfo/smtp-auth
    
    AuthInfo: "U:root" "I:[email protected]" "P:PASSWORD"
    

    Now create a hash map file of above created auth file.

    makemap hash /etc/mail/authinfo/smtp-auth < /etc/mail/authinfo/smtp-auth
    

    2. Configure Sendmail with SMART_HOST

    Now add following configuration lines into your sendmail.mc configuration file below "MAILER" definition.

     define(`SMART_HOST',`[smtp.gmail.com]')dnl
     define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
     define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
     define(`confAUTH_OPTIONS', `A p')dnl
     TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
     define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
     FEATURE(`authinfo',`hash -o /etc/mail/authinfo/smtp-auth.db')dnl
    

    In the next step we will need to re-build sendmail's configuration. To do that execute:

    make -C /etc/mail
    

    3. Verify Setup

    After completing all the above configuration's, reload the sendmail service to apply changes.

    sudo service sendmail reload
    

    Now send a test email to verify everything is working fine.

    echo "Test Email" | mail -s "Subject Here" [email protected] 
    

    Gmail sendmail smtp
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Configuring Sendmail through the External SMTP relay

    Postfix: Sending Emails From External SMTP Servers

    Postfix: Sending Emails From External SMTP Servers

    Postfix: Configure SASL Authentication for Remote SMTP

    Postfix: Configure SASL Authentication for Remote SMTP

    View 10 Comments

    10 Comments

    1. Nemanja on December 10, 2020 11:18 am

      Very nice guide, thanks! 🙂

      P.S. Unrelated to the topic: The submit button on the comment form covers the Captcha, there are only few pixels available to click on it.

      Cheers!

      Reply
    2. Filipi Souza on May 29, 2020 5:30 pm

      In CentOS 7, I needed of the packet cyrus-sasl-plain to send e-mails by relay auth.

      Reply
    3. Coreigh Utegaard on May 26, 2020 9:51 pm

      I tried it as posted and got a permission denied with and without sudo. This is due to the redirection in the command string.

      Step #1 part 4 should be slightly different
      sudo /bin/su -c “makemap hash /etc/mail/authinfo/gmail-auth < /etc/mail/authinfo/gmail-auth"

      found here: https://serverfault.com/questions/792675/sudo-makemap-permission-denied?noredirect=1&lq=1

      Reply
    4. Carlos on August 14, 2019 3:36 pm

      Thanks Rahul, it worked beautifully!!!!

      Reply
    5. scorp13 on May 3, 2019 1:39 pm

      I tried this method for sending service letters from DB server through an already configured SMTP on another server. Everything works perfectly!
      The only clarification on point 2: I had the following lines in the sendmail.mc file
      MAILER_DEFINITIONS
      MAILER (`local ‘) dnl
      MAILER (`smtp ‘) dnl
      So, the code snippet specified in the manual should be added after MAILER_DEFINITIONS, but BEFORE any MAILER (…, otherwise an error will occur: ERROR: FEATURE () should be before MAILER ()

      Reply
    6. Abhilash on February 21, 2019 1:02 am

      can you please attach the sendmail.mc file? the post is a little confusing for the newbie.

      Thanks

      Reply
    7. Jerry on August 27, 2018 2:33 am

      Noticed a small error – you request the user create:
      $ sudo mkdir /etc/mail/auth

      However, in step 3 you direct them to put the following in sendmail.mc:
      FEATURE(`authinfo’,`hash -o /etc/mail/authINFO/smtp-auth.db’)dnl

      This will cause an error. Thanks!

      Reply
      • chris on July 8, 2020 4:11 pm

        I will back this up. I needed to change too to work.

        Reply
    8. Rodel on March 15, 2018 3:56 am

      Hello Rahul,

      I have followed the steps above and I have used Gmail as the sender. I tried the command (echo “Test Email” | mail -s “Subject Here” [email protected] ) and I get this response ‘You have new mail in /var/mail/appadmin’ but i did not receive any email in my inbox? Did I missed something?

      Thank you

      Reply
      • Rahul K. on March 15, 2018 10:57 am

        Have you changed the recipient address?

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.