OpenSMTPD as MTA relay on OpenBSD 5.1

       229 words, 2 minutes

On my servers, I don’t want mail alerts to stay locally but to be forwarded to root@. There are two ways to do so: either put a .forward file in the home of service user that may send e-mail or configure the local MTA to forward email to root@. Depending on your local MTA, this can be more or less complicated. Usually, I end using sSMTP.

But this time, I want to do it using OpenSMTPD. Here’s how.

First of all, do not expect too much from this article, I’m just concatenating EXAMPLES from smtpd(8) and smtpd.conf(5). Then, since OpenBSD is installed:

  # pkill sendmail
  
  # vi /etc/mailer.conf
  sendmail        /usr/sbin/smtpctl
  send-mail       /usr/sbin/smtpctl
  mailq           /usr/sbin/smtpctl
  makemap         /usr/libexec/smtpd/makemap
  newaliases      /usr/libexec/smtpd/makemap
  
  # vi /etc/rc.conf.local
  (...)
  sendmail_flags=NO
  smtpd_flags=""
  
  # vi /etc/mail/smtpd.conf
  listen on lo0
  
  map "aliases" { source db "/etc/mail/aliases.db" }
  map secrets { source db "/etc/mail/secrets.db" }
  
  accept for all relay via mail.tumfatig.net tls auth "secrets"
  
  # touch /etc/mail/secrets
  # chmod 640 /etc/mail/secrets
  # chown root:_smtpd /etc/mail/secrets
  # echo "mail.tumfatig.net username:password" > /etc/mail/secrets
  # makemap /etc/mail/secrets
  
  # /etc/rc.d/smtpd start                                                                  
  smtpd(ok)

The only “problem” here is that all mail will have an envelope containing the server’s hostname ; which may/will lead to NDR such as “550 (…) Recipient address rejected: Domain not found”. The feature for masquerading e-mail is not yet implemented in OpenSMTPD. But will probably be when OpenBSD 5.2 is released.