Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Postfix


Updating the Postfix configuration to use SendGrid as a relay host is easy. For more advanced configuration scenarios, you'll need to refer to the Postfix documentation.

(error)

Danger

Some implementations of Postfix only allow passwords to contain letters and numbers, meaning you may need to ensure your SendGrid password is only alphanumeric.

Find your Postfix config file, typically /etc/postfix/main.cf, and add the following:


_10
smtp_sasl_auth_enable = yes
_10
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
_10
smtp_sasl_security_options = noanonymous
_10
smtp_sasl_tls_security_options = noanonymous
_10
smtp_tls_security_level = encrypt
_10
header_size_limit = 4096000
_10
relayhost = [smtp.sendgrid.net]:587

(information)

Info

We highly recommend using an API key as your credential for any service that supports it. API keys are both more secure and easier to work with.

Now you need to specify your credentials (use apikey as username and an API Key as password) in the separate file /etc/postfix/sasl_passwd (you'll likely need to create it):


_10
[smtp.sendgrid.net]:587 apikey:yourSendGridApiKey

Next, make sure the file has restricted read and write access only for root, and use the postmap command to update Postfix's hashtables to use this new file:


_10
sudo chmod 600 /etc/postfix/sasl_passwd
_10
sudo postmap /etc/postfix/sasl_passwd

Finally, restart Postfix:


_10
sudo systemctl restart postfix

(information)

Info

If you are getting no mechanism available error messages, it generally indicates that you are missing some SASL authentication libraries.

Install the missing module dependency using apt-get (i.e., Debian, Ubuntu):


_10
apt-get install libsasl2-modules

Or using a yum (i.e., RedHat, Fedora, CentOS):


_10
yum install cyrus-sasl-plain


Troubleshooting

troubleshooting page anchor

If port 587 is not working for you, please try 2525 in your postfix config. You may also need to edit /etc/postfix/master.cf to remove # from tlsmgr unix - - n 1000? 1 tlsmgr.

For other potential errors, please navigate to the default maillog file on your server for debugging purposes. For a CentOS server, the file is in path /var/log/maillog by default.

This file not only reports that the server was unable to use SendGrid to send email but also serves as an excellent debugging tool for new users that catalogues server parameters.


Rate this page: