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 Install OpenSNMPD if you want to try it out today.
First install postfix with the SASL flavour. SASL version of Postfix includes the SMTP authentication used by my ISP.
# pkg_add ftp://ftp.sunet.se/pub/OpenBSD/4.0/packages/amd64/postfix-2.3.2-sasl2.tgz
Replace sendmail with postfix as stated from the package install script.
/usr/local/sbin/postfix-enable
If you want to restore sendmail issue.
/usr/local/sbin/postfix-disable
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.
sendmail_flags="-bd"
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/main.cf. Most default values are sensible but some changes are needed depending on setup. Make the following changes.
# Specify your domain specifics
myhostname = balrog.lounge.se
myorigin = $mydomain
# Only allow mail from local host
inet_interfaces = 127.0.0.1
# Specify domains where this server is final destination
mydestination = $myhostname, localhost.$mydomain, localhost
# Relay mail to your ISPs mail server
relayhost = smtp.pixelgames.org
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
smtp.pixelgames.org user.name@gmail.com:password
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. main.cf) 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 ...
.
EOT
Also try to send a local mail to root.
mail root
Subject: Postfix test mail to ROOT
Message text ...
.
EOT
Check mail log to see that see if all worked out fine.
cat /var/log/maillog