Nethence Newdoc Olddoc Lab Your IP BBDock  


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

UnixWindowsOracleObsoleteHardwareDIYMechanicsScriptsConfigs

Setting up Postfix
on netbsd 7
 
http://pbraun.nethence.com/unix/mail/postfix.html
http://pbraun.nethence.com/unix/mail/dovecot.html
 
Basic ougoing setup
Setup mail aliases for root and admin user,
cd /etc/mail/
vi aliases
newaliases
 
Setup a smarthost,
cd /etc/postfix/
cat >> main.cf <<EOF
relayhost = SMARTHOST
EOF
/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
hostname
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.example.net host
natted_ip host.example.net host
 
Backup and eventually clean-up the config file,
cd /etc/postfix/
mv main.cf main.cf.dist
sed '/^#/d; /^ *$/d;' main.cf.dist > main.cf
sed '/^#/d; /^ *$/d;' main.cf.dist > main.cf.dist.clean
 
Enable listen on port 25,
cd /etc/postfix/
cp master.cf master.cf.dist
vi master.cf
smtp...smtpd
 
Setup myorigin in main.cf and reload,
cd /etc/postfix/
cp main.cf main.cf.dist
vi main.cf
myorigin = example.net 
/etc/rc.d/postfix restart
 
Add this to main.cf,
mydestination = $mydomain, example.net, $myhostname, host.example.net, mx.example.net, mx2.example.net, localhost.$mydomain, localhost, 127.0.0.1 
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::0:0::0:0:host.example.net &:/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
ORGMAIL=${HOME}/Maildir/
DEFAULT=${ORGMAIL}
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)
 
Maintenance
Add some users,
groupadd mailusers
useradd -g mailusers -s /sbin/nologin -m mailuser 
 
Check the mail queue,
mailq
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
root@netbsd2.example.net root@example.net
admin@netbsd2.example.net admin@example.net
cat >> main.cf <<EOF
smtp_generic_maps = hash:/etc/postfix/generic
EOF
postmap generic
/etc/rc.d/postfix restart
 
Troubleshooting
If you get this error,
mail for host.example.net 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
mailq
Ref. https://rbgeek.wordpress.com/2013/01/06/how-to-fix-postfix-file-too-large-error/
 
References
https://www.netbsd.org/docs/guide/en/chap-mail.html
http://www.postfix.org/BASIC_CONFIGURATION_README.html
 

(obsolete, see the new doc)