分类: BSD
2007-11-22 02:09:02
This document is written for configuring a OpenBSD 3.4-based mailserver, however it there is no reason it should not apply to versions as old as OpenBSD 3.0 or something newer.
_3_4
to _3_1
.
# export CVSROOT=anoncvs@anoncvs1.usa.openbsd.org:/cvs
# cd /usr
# cvs -q up -rOPENBSD_3_4 -P src
To update this tree later simply cd /usr/src; cvs -q up -rOPENBSD_3_4 -Pd
# cd /usr/src/sys/arch/i386/conf
# /usr/sbin/config GENERIC
# cd /usr/src/sys/arch/i386/compile/GENERIC
# make clean && make depend && make
# cd /usr/src/sys/arch/i386/compile/GENERIC
# cp /bsd /bsd.old (Save an old copy of your kernel)
# cp bsd /bsd (Copy the new kernel into place)
# reboot
# cd /usr/src
# rm -r /usr/obj/*
# make obj && make build
Reboot the machine, at this point it's safe to connect it to the internet
# export CVSROOT=anoncvs@anoncvs1.usa.openbsd.org:/cvs
# cd /usr
# tar -xvzf /path/to/ports.tar.gz
# cvs -q up -rOPENBSD_3_1 ports
# cd /usr/ports/mail/postfix
Optionally, edit Makefile and uncomment out all the SUBDIR+= except for: SUBDIR+= stable,pcre,tls
# make install
#sendmail_flags="-L sm-mta -C/etc/mail/localhost.cf -bd -q30m"
and add:
sendmail_flags="-bd -q30m"
#*/30 * * * * /usr/sbin/sendmail -L sm-msp-queue -Ac -q
mydomain = your domain here
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, $mydomain
home_mailbox = .maildir/ # NOTE: the trailing / is important
# mailbox_command = /usr/local/bin/procmail
Leave mailbox_command commented out for now. After procmail is configured it will be uncommented.
# postfix check
# postfix start
At this point send a test message to a local user, his mail directory should be created $HOME/usrname/.maildir along with sub directories /new /cur /tmp with the new mail being in /new
# cd /usr/ports/mail/mutt
# SUBDIR += snapshot
# make install
cd /etc/Mutt
set mbox_type=Maildir
set folder=~/.maildir
set spoolfile=~/.maildir/
This allows Mutt to read Maildir format mailboxes
# cd /usr/ports/mail/procmail
# make fetch extract
# cd /usr/ports/mail/procmail/w-procmail-3.22/procmail-3.22/src
#define MAILSPOOLDIR "/var/spool/mail/"
to:
#define MAILSPOOLDIR ""
change line:
#define MAILSPOOLHOME "/.mail"
to:
#define MAILSPOOLHOME "/.maildir"
# make install
add line at top of file:
DEFAULT=$HOME/.maildir/
mailbox_command = /usr/local/bin/procmail
# postfix reload
Again you want to send another test message at this point to make sure that procmail is now delivering the mail correctly to the users .maildir mailbox
# cd /usr/ports/mail/courier-imap
# make install
# cd /etc; mkdir courier-imap
# cd courier-imap; cp /usr/local/share/examples/courier-imap/* .
Configure the file for your server
# mkimapdcert
This reads imapd.cnf and creates an imap ssl certificate in /etc/ssl/private/imapd.pem
Set:
AUTHDAEMOND="authdaemond.plain"
Set at the end of the file:
MAILDIR=.maildir
IMAPDSTART=YES
# /usr/local/libexec/authlib/authdaemond start
# /usr/local/libexec/imapd.rc start
# /usr/local/libexec/imapd-ssl.rc start
You might want to put the above into a shell script you can call from /etc/rc.local for startup
At this point you should be able to test out imap access with your favorite mail client.
Grab pop-before-stmp from its website: and untar into a temp directory like /usr/local/src/pop-before-smtp
uncomment the line under: # Override the DB hash file we will create/update (".db" gets appended).
$dbfile = '/etc/postfix/pop-before-smtp';
uncomment:
$logto = '/var/log/pop-before-smtp';
change the line under: # Set the log file we will watch for pop3d/imapd records. to read:
$file_tail{'name'} = '/var/log/maillog';
uncomment the line under: # For Courier-POP3 and Courier-IMAP:
$pat = '^(... .. ..:..:..) \S+ (?:courier)?(?:pop3|imap)(?:login|d|d-ssl): ' .
'LOGIN, user=\S+, ip=\[[:f]*(\d+\.\d+\.\d+\.\d+)\]$';
comment out the lines to tell it to use NDBM database:
#=pod #------------------------ Postfix NDBM_File ---------------------START-
#=cut #------------------------ Postfix NDBM_File -----------------------END-
# cp pop-before-smtp-conf.pl /etc
# cp pop-before-smtp.init /etc
# cp pop-before-smtp /usr/sbin
/etc/pop-before-smtp.init start
You should see a list of ip addresses etc in /var/log/pop-before-smtp from your imap tests. You should also have a database file in /etc/postfix/pop-before-smtp.db
Add the following line:
smtpd_recipient_restrictions = permit_mynetworks,reject_non_fqdn_recipient,check_client_access
hash:/etc/postfix/pop-before-smtp,check_relay_domains
Reload postfix settings:
# postfix reload
You should be able to verify that postfix will now refuse to accept mail from remote (non local network) connections without logging in via imap or pop3 first.
Spamassassin requires HTML-Parser perl module as a prereq so we'll start there.
# cd /usr/ports/www/p5-HTML-Parser
# make install
Now onto the spamassasin install
# mkdir /usr/local/src
# cd /usr/local/src
# tar -xvzf /path/to/downloaded/Mail-SpamAssassin-2.41.tar.gz
# perl Makefile.PL
# make
# make install
Lets test the install:
# spamassassin -t < sample-nonspam.txt > nonspam.out
# spamassassin -t < sample-spam.txt > spam.out
This runs spamassasin in test, by reading the spam.out file and nospam.out file you can see what it does to each mail message.
At this point spamassassin is ready to be setup in procmail, you can either set it up system wide or in my case on a user by user basis.
# cd ~
# maildirmake -f Spam .maildir
This creates a maildir folder inside your ~/.maildir called .Spam
:0fw
| spamassassin -P
:0:
* ^X-Spam-Status: Yes
$HOME/.maildir/.Spam/
Now simply kick back and watch most if not all of your incoming spam get tagged and redirected into your new imap folder Spam.