Skip to content

Relay outbound email through SendGrid

A common approach for improving email delivery success rates is to send email through a transactional email delivery service such as SendGrid.

To configure your server’s mail transfer agent, Postfix, to relay all email through SendGrid, perform the steps below.

First, SSH in to your server as root and run the following command to install the libraries required for Postfix to authenticate to SendGrid using your SendGrid credentials:

Terminal window
sudo apt-get install libsasl2-modules

Next, edit the file /etc/postfix/main.cf and add the following lines:

/etc/postfix/main.cf
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:yourSendGridUsername:yourSendGridPassword
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587

Finally, save the file and restart Postfix:

Terminal window
sudo service postfix restart