Thorsten Zöller

Relay Mail to a Remote SMTP Server With smtpd

Configure smtpd(8) to relay outgoing mail to a remote SMTP server as follows:

Create the file /etc/mail/secrets:

# doas touch /etc/mail/secrets
# doas chmod 640 /etc/mail/secrets
# doas chown root:_smtpd /etc/mail/secrets
# doas echo "label username:password" > /etc/mail/secrets

username and password are the credentials for accessing the remote SMTP server, and label is an identifier for the username-password combination. It can be chosen arbitrarily and is used in smtpd.conf (see below). Since the credentials are stored in plain text, restrictive permissions are set for the secrets file.

Replace the default content of /etc/mail/smtpd.conf with the following:

table aliases file:/etc/mail/aliases
table secrets file:/etc/mail/secrets

listen on lo0

action "local" mbox alias <aliases>
action "relay" relay host smtp+tls://label@smtp-server:port auth <secrets>

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

label is the corresponding label from the secrets file, smtp-server is the URL of the remote SMTP server, and port is the mail submission port (default: 587).

Verify that the configuration is syntactically correct:

# doas smtpd -n
configuration OK

Restart smtpd:

# doas rcctl restart smtpd

Test the configuration by sending an e-mail using mail(1):

# echo "body" | mail -s "subject" email-address