Skip to content

Instantly share code, notes, and snippets.

@josectheone
Created October 3, 2019 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josectheone/a86b58eb71f25dcfe4b54ae590994cc7 to your computer and use it in GitHub Desktop.
Save josectheone/a86b58eb71f25dcfe4b54ae590994cc7 to your computer and use it in GitHub Desktop.
Configure sendmail to use smtp relay
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:user@gmail.com" "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" recipient@example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment