Install Postfix

Setup Postfix on OpenBSD


The main reasons for changing OpenBSD default sendmail for Postfix is that it is much easier to configure. A lot of documentation is also available on internet. See some references below.

The setup described here is a very simple setup where all outgoing mails are relayed to the mail server of your ISP. Only mails from local host is allowed.

A even simpler setup is described ReallySimplePostfixInstallation.

Another guide specifically for relaying mail to gmail.

Very soon there will be a really attractive alternative to postfix, OpenSMTPD. OpenSMTPD is very close to being production ready and the configuration seems to be at least as simple as for Postfix. OpenSMTPD is developed primarily towards OpenBSD and inherit much of its philosophy of simple and clean solution. See man smtpd for setup intructions and man smtpd.conf for configuration examples if you want to try it out today. You should be running OpenBSD -current.

Install packages

First install postfix with the SASL flavour. SASL version of Postfix includes the SMTP authentication used by my ISP.

# pkg_add

Replace sendmail with postfix as stated from the package install script.


If you want to restore sendmail issue.


Make the changes requested from postfix-enable. Add the following lines to /etc/rc.conf.local. Note that /etc/rc.conf.local supercedes settings in rc.conf.

syslogd_flags="-a /var/spool/postfix/dev/log"

Also remove clientmqueue from from root cron tab in /var/cron/tabs/root by commenting out the following line.

# */30  *       *       *       *       /usr/sbin/sendmail -L sm-msp-queue -Ac -q

Edit Postfix main configuration file /etc/postfix/ Most default values are sensible but some changes are needed depending on setup. Make the following changes.

# Specify your domain specifics
myhostname =
myorigin = $mydomain
# Only allow mail from local host
inet_interfaces =
# Specify domains where this server is final destination
mydestination = $myhostname, localhost.$mydomain, localhost
# Relay mail to your ISPs mail server
relayhost =
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
# Relay mails to unknown receipents to root account
luser_relay = root

Put gmail login in /etc/postfix/sasl_passwd

Create sasl_passwd.db file by issuing.

postmap /etc/postfix/sasl_passwd

Link to sendmail’s aliases file

ln -s /etc/mail/aliases /etc/aliases

Make sure that root alias point to local host. Otherwize mails to root will be relayed to your ISP which isn’t a good idea!

root:           root@localhost

Update aliases by issuing.

postalias /etc/mail/aliases

Initialize alias database by issuing.


Restart syslogd.

kill -HUP <pid-of-syslogd>
postfix start

After each change of any postfix configuration (e.g. you must reload posfix configuration via.

postfix reload

Try to send a mail using UNIX standard mail client mail.

mail <external mail address>
Subject: Postfix test mail
Message text ...

Also try to send a local mail to root.

mail root
Subject: Postfix test mail to ROOT
Message text ...

Check mail log to see that see if all worked out fine.

cat /var/log/maillog