Setting up openSMTPD with an external relay

Published September 20, 2020

I have a build VM which I use to build my arch packages and I want to receive emails when the build of a packages causes errors. Due to my build script, most packages will not be continuously rebuilt if they were failing, so it is important that there is some notification when a build fails. Email seems like a good option for this as there are many tools available for it, and it is easily to send from the command line. The problem is that I need to set up a mail relay to access the SMTPD server in order to send mail. I used OpenSMTPD as it seemed easier to set-up than Postfix. This only focuses on the sending of mail, as that is all a build VM should do.

The file, /etc/smtpd/smtpd.conf needs to be configured to send external emails. This is done by adding the external relay and allowing any external mail to be sent through that email. The file should look like this:

table aliases file:/etc/smtpd/aliases
table secrets file:/etc/smtpd/secrets

listen on localhost

action "local" maildir alias <aliases>
action "relay" relay host "smtps://build@mail.joelg.net" auth <secrets> mail-from "@joelg.net"

match from local for local action "local"
match from local for any action "relay"

This allows any internal mail to be send internally, but all external mail to be sent as such. The login details for the server needs to be created in /etc/smtpd/secrets in the following format.

build user:password

There is no need to modify the aliases file. After this, start smtpd.service and try sending a test email. The queue can be viewed with smtpctl show queue. After a few seconds the email should be received on the other end.

Overall this isn’t too complex, although there are a few errors which can be encountered and the lack of tutorials available online doesn’t help. I hope this helps a little, let me know if there’s anything that’s changed or that I missed.