Most of the providers these days are blocking the default port 25 and users find it difficult to get around it. If you are looking at sending very less mails and do not want to go for paid stuffs, this is for you.
We will see how we can intergrate Postfix with Sendgrid which allows 40,000 emails for 30 days, then 100/day forever
First create an account at sendgrid, and get the API key, you would want this to be pasted in postfix configuration file.
Make sure to verify your domain at sendgrid ( https://sendgrid.com/docs/glossary/domain-authentication/ )
Also verify a sender address from the domain you would be using for mailing ( https://sendgrid.com/docs/ui/sending-email/sender-verification/ )
Once that is done, lets move to the postfix configuration :
Open /etc/postfix/main.cf and type in these values :
smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_sasl_tls_security_options = noanonymous smtp_tls_security_level = encrypt header_size_limit = 4096000 relayhost = [smtp.sendgrid.net]:587
As mentioned in the config file, we will need to create /etc/postfix/sasl_passwd file where we will store the API key.
It would be in the format : ( username by default is apikey )
# chmod 600 /etc/postfix/sasl_passwd # postmap /etc/postfix/sasl_passwd # systemctl restart postfix
Lets test if this is working by using the mail command
If not present, install it
apt-get install mailutils
echo "the body of the mail" | mail -r firstname.lastname@example.org -s "my subject" email@example.com
The mail firstname.lastname@example.org should be the email address you have verified in sendgrid.