Setup OpenSMTPD on OpenBSD

opensmtpd logo

Basic mail setup in OpenBSD is quite straight forward.

To avoid major problems you should avoid to "relay external mail to external mail servers".

To deliver local mail externally or receive external mail to local is easy enough.

Route local externally via GMail

The guide from router project covers it.

# cat smtpd.conf

listen on lo0
table aliases db:/etc/mail/aliases.db
table secrets db:/etc/mail/secrets.db
accept for local alias <aliases> deliver to mbox
accept from local for any relay via tls+auth:// auth <secrets>

# cat secrets


Make sure secrets file are secure!

chmod 640 secrets 
chown root:_smtpd secrets

Receive external mail

To receive mail externally you may be a little more cautious.

I use a senders file to restrict allowed senders.

# cat senders_allowed

In this case I also use a different outgoing mail server using SSL (not TLS)

# cat secrets 
mailprovider user:password

# cat smtpd.conf

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

listen on all
accept sender <senders_allowed> for domain "" alias <aliases> deliver to mbox

# Local mails to mbox
accept for local alias <aliases> deliver to mbox

# Local mail to external via mailprovider
accept from local for any relay via secure+auth:// auth <secrets>


See mailgun for hosted mail service