Postfix 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.
See Also:
Install Required Packages:
First we need to install postfix packages. You mention command you install the required packages as per your OS flavor.
For RHEL/CentOS 6/7
# yum install cyrus-sasl-plain postfix
For Ubuntu 16.04/18.04
# apt-get install libsasl2-modules postfix
Configuration:
Edit or create /etc/postfix/sasl_passwd file and add the SendGrid information in the file.
# vim /etc/postfix/sasl_passwd
[smtp.sendgrid.net]:587 yourSendGridUsername:yourSendGridPassword
Run the following command to restrict read and write from users and update Postfix hashtable using postmap command.
# chmod 600 /etc/postfix/sasl_passwd # postmap /etc/postfix/sasl_passwd
Postfix Configuration:
Now do the postfix configuration to use SendGrid as our smart host.
# vim /etc/postfix/main.cf
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
Restart Postfix
Now restart the Postfix service using following commands.
For RHEL/CentOS 7 & Ubuntu 18.04
# systemctl start postfix
# systemctl enable postfix
For RHEL/CentOS 6 & Ubuntu 16.04
# service postfix start
# chkconfig postfix off
Test Postfix Configuration:
Test the changes by using the following mail command.
#echo "SendGrid and Postfix Configuration" | mail -s "Mail Subject" support@techoism.com
Reference:
Enjoy it!