Pragmatism in the real world

Updating SMTP relay in postfix

On a server that I help to maintain, it has postfix installed for emailing results of cron jobs and other status updates. This was set up to relay through SendGrid as they had a 100 email per month plan and we send out significantly fewer than that.

Unfortunately, SendGrid are retiring their free plan, so I had to move to a new service and picked SMTP2GO and so had to update the postfix configuration. As I didn’t have this written down, I’m noting in here.

Get SMTP details

You need the SMTP hostname, SMTP username and SMTP password. SMTP2GO allows you to have multiple usernames and usefully allows you to rate limit each one individually, should you need that.

Configure postfix

Firstly, update /etc/postfix/main.cf

Find relayhost and change to [mail.smtp2go.com]:587. I’m just updating, so the rest of the settings I left alone.

However, the relevant settings are:

relayhost = [mail.smtp2go.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_use_tls = yes

Secondly, add the new SMTP user’s credentials

Edit /etc/postfix/sasl_passwd. This needs to be done as root as the permissions on this file are 600 and it’s owned by root:root.

Add a new line with this format:

[mail.smtp2go.com]:587 {username}:{password}

Where {username} is the SMTP username and {password} is the SMTP password.

Save the file and then create the hash database:

sudo postmap /etc/postfix/sasl_passwd

Restart postfix

That’s it, so just restart postfix with sudo service postfix restart

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *