SendMail and SendGrid Configuration Server-Side on CentOS/RHEL/Ubuntu

SMTP (Simple Mail Transfer Protocol) is a easy way to send email from one server to another. SendGrid provides an SMTP service that allows you to deliver your email via our server instead of your client or server.

SendGrid Configuration Server

See Also:

Install Required Packages:

First, we need to install sendmail packages. Use mention command you install the required packages as per your OS flavor.

For RHEL/CentOS 6/7

# yum install cyrus-sasl-plain sendmail sendmail-cf

For Ubuntu 16.04/18.04

# apt-get install libsasl2-modules sendmail sendmail-cf heirloom-mailx

Configuration:

Edit the mail access file and add the SendGrid information in the file.

# vim /etc/mail/access 
AuthInfo:smtp.sendgrid.net "U:YOUR_SENDGRID_USER" "P:YOUR_SENDGRID_PASSWORD" "M:PLAIN"

Run the following command to generate the access.db database map:

# makemap hash /etc/mail/access.db < /etc/mail/access 

SendMail Configuration:

Now do the sendmail configuration to use SendGrid as our smart host.
For RHEL/CentOS

# vim /etc/mail/sendmail.mc

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

For Ubuntu

# vim /etc/mail/sendmail.mc
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:

To make your changes accessible to Sendmail, regenerate sendmail configuration file using the m4 command.

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Restart SendMail

Now restart the Sendmail service using following commands.

# service sendmail restart

Test SendMail Configuration:

Test the changes by using the following mail command.

#echo "SendGrid and SendMail Configuration" | mail -s "Mail Subject" support@techoism.com

Reference:

SendGrid Official Website

Enjoy it!


No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.