E. Preliminary configuration and testing of OpenSMTPD
1. At this point, we might should go ahead and install all the other packages needed:
pkg_add opensmtpd-extras opensmtpd-filter-rspamd dovecot dovecot-pigeonhole rspamd redis
2. OpenSMTPD is installed in base. First, copy the default smtpd.conf:
doas cp /etc/mail/smtpd.conf /etc/mail/smtpd.conf.default
Then create your new smtpd.conf like so:
# smtpd.conf
# PKI keys for TLS
pki mail cert "/etc/ssl/mail.example.com.fullchain.pem"
pki mail key "/etc/ssl/private/mail.example.com.key"
# Tables
table aliases file:/etc/mail/aliases
table credentials passwd:/etc/mail/credentials
table virtuals file:/etc/mail/virtuals
# Listeners
listen on all tls pki "mail" hostname "mail.example.com"
listen on egress port submission tls pki "mail" hostname "mail.example.com"
# Actions
action "local_mail" mbox alias <aliases>
action "domain_mail" maildir "/var/vmail/example.com/%{dest.user:lowercase}" \
virtual <virtuals>
action "outbound" relay
# Rules
# Local
match from local for local action "local_mail"
match from local for domain "example.com" action "domain_mail"
match from local for any action "outbound"
# Remote
match from any for domain "example.com" action "domain_mail"
match from any for any action "outbound"
We'll flesh this out after dovecot and rspamd are set up.
3. Check configuration and restart smtpd:
doas smtpd -nf /etc/mail/smtpd.conf
doas rcctl restart smtpd
4. Check if it's working by sending messages from a local user to domain address:
mail -s "Test mail from local user" john@example.com
John,
This might work.
Cheers
ctrl-d
Check if the mail is received:
doas ls -al /var/vmail/example.com/john/new/
Once you're sure that it works, go ahead and stop smtpd because this configuration allows your server to be an open relay. We'll finish up OpenSMTPD configuration later.
Next: PF configuration
Previous: Virtual users
Posted by Gordon, No Hair Github Pages, August 24, 2021
© nohair.net and the author
For comments, corrections, and addenda, email: gordon[AT]nohair.net