Nethence Newdoc Olddoc Lab Your IP BBDock  

Warning: those guides are mostly obsolete, please have a look at the new documentation.


Setting up Postfix
on netbsd 7
Basic ougoing setup
Setup mail aliases for root and admin user,
cd /etc/mail/
vi aliases
Setup a smarthost,
cd /etc/postfix/
cat >> <<EOF
relayhost = SMARTHOST
/etc/rc.d/postfix restart
Basic MX server setup for local unix user delivery as Maildir format
Setup the system hostname,
cd /etc/
vi myname
/etc/rc.d/network restart
also make sure the public and eventually natted local IPs are defined in the hosts file (not it's also prefered to put the fqdn at first for other purposes, think Apache),
public_ip host
natted_ip host
Backup and eventually clean-up the config file,
cd /etc/postfix/
sed '/^#/d; /^ *$/d;' >
sed '/^#/d; /^ *$/d;' >
Enable listen on port 25,
cd /etc/postfix/
Setup myorigin in and reload,
cd /etc/postfix/
myorigin = 
/etc/rc.d/postfix restart
Add this to,
mydestination = $mydomain,, $myhostname,,,, localhost.$mydomain, localhost, 
Note. the local hostname (or whatsever you define as myorigin) needs to be included into mydestination otherwise you will get the loop to myself error.
Note. if you enable myorigin, when you receive daily cron emails and want to see the hostname of the box, this workaround,
vipw &:/root:/bin/ksh
To enable Maildir,
home_mailbox = Maildir/
alternatively, enable procmail for all the users to enable Maildir,
echo $PKG_PATH
pkg_add procmail
cd /etc/
ln -s /usr/pkg/etc/procmailrc
vi /etc/procmailrc
mailbox_command = /usr/pkg/bin/procmail
Ready to go
Read the logs,
tail -f /var/log/maillog
Enable the daemon,
echo "postfix=YES" >> /etc/rc.conf
/etc/rc.d/postfix restart
Check that everything is fine,
ps aux | grep post
netstat -an -f inet,inet6
Do some tests,
date | mail -s toroot root (alias to real email)
date | mail -s toadminuser adminuser (alias to root)
date | mail -s tomailuser mailuser (local user)
date | mail -s tononexistent nonexistent (should return to postmaster)
Add some users,
groupadd mailusers
useradd -g mailusers -s /sbin/nologin -m mailuser 
Check the mail queue,
eventually force the delivery of the messages that stayed in the queue,
sendmail -q
In case you didn't switch to Maildir, install Pine to read local delivery returns as root,
echo $PKG_PATH
pkg_add pine
It actuall deals with INBOX /var/mail/USER as well as ~/mbox.
Additional notes
If you need to rather fine tune some users specificly,
cd /etc/postfix/
vi generic
cat >> <<EOF
smtp_generic_maps = hash:/etc/postfix/generic
postmap generic
/etc/rc.d/postfix restart
If you get this error,
mail for loops back to myself
==> make sure the local hostname is added to mydestination or that the myorigin is added to mydestination
If you get this error in maillog under production,
...status=bounced (cannot update mailbox /var/mail/USERNAME for user USERNAME. error writing message: File too large)
==> fix the max size,
postconf -e mailbox_size_limit=0
postconf -e message_size_limit=0
systemctl restart postfix

(obsolete, see the new doc)