Having a mail tansfer agent, waiting for a pipe input right there in our $SHELL
is a blessing.
Luckily for us, OpenBSD comes with a nifty thing called smtpd, which can be
configured via smptd.conf(5).
Let's make a file, /etc/mail/secrets
as root. And in it add your relay,
which is a fancy term for what you wanna call the service, you wanna use to send your mail.
Well, the technical definition is
"SMTP Relays lets you send email messages through your email account using your existing email client". Nuff said!
$ doas cat /etc/mail/secrets
# myrelay relay_username:relay_password
fmail [email protected]:5tr0ngP4ssw0rd
Add a little bit of security to that file by locking down its permissions.
$ doas chown root:_smtpd /etc/mail/secrets
$ doas chmod 640 /etc/mail/secrets
Now bust open /etc/mail/smtpd.conf
and change it like so
...
table aliases file:/etc/mail/aliases
table secrets file:/etc/mail/secrets
listen on lo0
action "local" mbox alias
action "relay" relay host smtp+tls://[email protected]:587 auth
match for local action "local"
match for any action "relay"
...
587
is the default port for SMTP on most mail providers.
Check if the config syntax is OK with $ doas smtpd -n
.
Now, do a $ doas rcctl restart smtpd
. The SMTP daemon should be working now.
Let's send a mail,
$ mail -s "A Test email from your OpenBSD machine" -r '[email protected]' [email protected]
Take a look at the mail(1) man page, before we get creative.
And before we end the article, do a $ doas tail -f /var/log/maillog
to the see the action.