Sending email via Gmail relay through sendmail

From Notes_Wiki

Home > CentOS > CentOS 6.x > Email server configuration > Sendmail server configuration > Sending email via Gmail relay through sendmail

To send email via Gmail relay through sendmail use:

  1. Configure gmail to use less secure apps using:
    1. Login into Gmail account and go to Settings -> Accounts -> Google Account Settings
    2. In "Google Account Settings" go to Sign-in and Security.
    3. In Sign-in and security change "Allow less secure apps:" to ON
  2. edit /etc/mail/sendmail.mc and add following lines after commented SMART_HOST line
    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_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
    FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
  3. create /etc/mail/auth and /etc/mail/auth/client-info with following contents:
    AuthInfo:smtp.gmail.com "U:root" "I:<gmail-email-address>" "P:<gmail-password>" "M:PLAIN"
    AuthInfo:smtp.gmail.com:587 "U:root" "I:<gmail-email-address>" "<gmail-password>" "M:PLAIN"
  4. chmod 700 /etc/mail/auth
  5. chmod 600 /etc/mail/auth/client-info
  6. cd /etc/mail/auth
  7. makemap hash client-info.db < client-info
  8. cd /etc/mail
  9. make
  10. service sendmail restart
  11. echo "Test email using sendmail" | mail -s "Gmail relay test" saurabh@sbarjatiya.com

For debugging refer to /var/log/maillog. In /var/log/maillog look at value of ctladdr such as 'ctladdr=<saurabh@localhost.localdomain>' to find out which local user will get the bounce message back. Then look for /var/mail/<username> file. You can also use mail command from given user and read the bounce messages to understand the issue being faced.



Home > CentOS > CentOS 6.x > Email server configuration > Sendmail server configuration > Sending email via Gmail relay through sendmail