June 30, 2015 - rob

How to use sendmail to send emails through an sendgrid server.

First we need to install some dependencies, some you might already have installed:

yum install sendmail sendmail-cf sendmail-doc cyrus-sasl-{lib,plain}

change to /etc/mail directory

cd /etc/mail

edit sendmail’s sendmail.mc configuration file and add/change the following

## cp sendmail.mc{,.orig}

## vim sendmail.mc

define(`PROCMAIL_MAILER_PATH’, `/usr/bin/procmail’)dnl

define(`confAUTH_OPTIONS’, `A’)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(local_procmail)dnl 

DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA’)dnl

DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea’)dnl 

MAILER(procmail)dnl

save and close the file and make sendmail’s configuration by running the following commands

cd /etc/mail

 make all

restart sendmail and add it to your linux vps start-up using systemctl

systemctl restart sendmail saslauthd

systemctl enable sendmail saslauthd

Set the authorization credentials in /etc/mail/access

  AuthInfo:smtp.sendgrid.net “U:yourUserName” “P:yourPassword” “M:PLAIN”

Define the Smart Host in /etc/mail/sendmail.mc You should add these lines just after the commented “#dnl define(‘SMART_HOST’, ‘smtp.your.provider’)dnl” line in the file

define(`SMART_HOST’, `smtp.sendgrid.net’)dnl

FEATURE(`access_db’)dnl

define(`RELAY_MAILER_ARGS’, `TCP $h 587′)dnl

define(`ESMTP_MAILER_ARGS’, `TCP $h 587′)dnl

Update sendmail.cf and access.db files

(You will need to run these commands as ‘su’ or ‘root’)

cd /etc/mail

m4 sendmail.mc >sendmail.cf

makemap hash access < access

On older distros, you can run restart sendmail like so:

/etc/init.d/sendmail restart

If, however, you’re using a newer version, do the following to restart:

service sendmail restart

Linux