Configuring server-side email delivery service for Sendmail and SendGrid
Use the following steps to configure your server to use the IBM Cloud® email delivery service with Sendmail.
This example is a bare metal installation of CentOS 6.5 and Ubuntu 14.
Pre-configuration
You need to install the following packages for Sendmail to properly use SendGrid as a smart host.
RHEL and CentOS
For RHEL and CentOS, run the following command:
yum install cyrus-sasl-plain sendmail sendmail-cf
Ubuntu and Debian
For Ubuntu and Debian, run the following command:
apt-get install libsasl2-modules sendmail sendmail-cf heirloom-mailx
Configuring SendGrid
-
Add your SendGrid username and password to the file /etc/mail/access:
AuthInfo:smtp.sendgrid.net "U:YOUR_SENDGRID_USER" "P:YOUR_SENDGRID_PASSWORD" "M:PLAIN"
-
Run the following command to generate the /etc/mail/access.db database map:
makemap hash /etc/mail/access.db < /etc/mail/access
-
Edit the /etc/mail/sendmail.mc file to use SendGrid as our smart host.
Configuring sendmail.mc in RHEL and CentOS
-
Locate and open the sendmail.mc file.
-
Comment out the following line.
dnl define('SMART_HOST', 'smtp.your.provider')dnl
-
Add new lines with the following code.
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
Configuring sendmail.mc in Ubuntu and Debian
-
Locate and open the sendmail.mc file.
-
At the end of the file, insert the following code before the line that reads 'MAILER_DEFINITIONS'
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
Regenerate sendmail.cf
The sendmail.mc file is a collection of macros that expand into the real (and more complex) sendmail.cf config file. To make your changes accessible to Sendmail, regenerate sendmail.cf by using the m4 command.
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Restart Sendmail
Restart Sendmail by using the following command:
service sendmail restart
Test changes by using the command line mail utility
Test the changes by using the following command:
echo "Sendgrid and Sendmail" | mail -s "mail subject here" you@yourdomain.com