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.
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:
Make sure to restart Postfix:
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
$ /etc/init.d/postfix restart
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):
Or using a yum (i.e., RedHat, Fedora, CentOS):
$ apt-get install libsasl2-modules
$ yum install cyrus-sasl-plain