Postfix, Courier, Squirrelmail and Spamassassin

From Gentoo Linux Wiki

Jump to: navigation, search

This guide will show you how to setup a mailserver with webmail and spam detection.

Contents

[edit] Maildirs

In order to create maildir's automatically when you create a new user run the following command.

mkdir -p /etc/skel/.maildir/{cur,new,tmp}

To create a maildir for users that already exist run the following command as that user.

mkdir -p /home/user/.maildir/{cur,new,tmp}

[edit] Postfix

emerge mail-mta/postfix

Edit the following file.

File: etc/postfix/main.cf
myhostname = hostname.domain.tld
mydomain = domain.tld
mydestination = /etc/postfix/mydestination

Create the /etc/postfix/mydestination file and put the domains this server accepts mail for. One domain per line.

File: etc/postfix/mydestination
domain1.tld
domain2.tld
domain3.tld
etc...

Run the following command. Postfix will not work correctly without it.

/usr/bin/newaliases

[edit] Courier Imap

Make sure you have the Use Flags: pam (?) set.

emerge net-mail/courier-imap net-libs/courier-authlib

Edit the following files. There will be other stuff in it, just delete it all and replace it with authpam.

File: /etc/courier/authlib/authdaemonrc
authmodulelist="authpam"
authmodulelistorig="authpam"
File: /etc/courier/authlib/ authdaemonrc.dist
authmodulelist="authpam"
authmodulelistorig="authpam"

[edit] Bind

emerge net-dns/bind

You will need to configure Bind with your DNS information so your domain works. I use Webmin (which is a web based admininstration script) to configure Bind. If you choose this method...

emerge app-admin/webmin
/etc/init.d/webmin start

You can now login to webmin at https://192.168.0.1:10000 or https://127.0.0.1:10000 depending on how your accessing it.

You need Apache and PHP installed and configured in order to use squirrelmail.

[edit] Apache with PHP

Make sure you have the Use Flags: apache2 (?) set.

emerge www-servers/apache php

The following Apache2 configuation will allow you to visit domain.tld and if you type www.domain.tld it will redirect you to domain.tld. Edit the following files.

File: /etc/apache2/vhosts.d/00_default_vhost.conf
<VirtualHost *:80>
DocumentRoot "/path/to/webroot"
ServerName domain.tld
<Directory "/path/to/webroot">
allow from all
Options +Indexes
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName www.domain.tld
Redirect / http://domain.tld/
</VirtualHost>

There will be other stuff in the following file. Just add -D PHP5 to the end of it

File: /etc/conf.d/apache2
APACHE2_OPTS="-D PHP5"

[edit] Squirrelmail

Squirrelmail is a web based mail client

emerge mail-client/squirrelmail
webapp-config -I -h localhost -d squirrelmail squirrelmail 1.4.17

Copy /var/www/localhost/squirrelmail into your webroot.

cp -R /var/www/localhost/squirrelmail /path/to/webroot/
cd /path/to/webroot/squirrelmail
./configure

Go to "Server Settings" and change your domain name. Select "A" and change your IMAP settings so your IMAP Server is courier.

[edit] SpamAssassin

emerge mail-filter/spamassassin

Edit the local.cf file. Here are some options to start with.

File: /etc/spamassassin/local.cf
rewrite_header Subject *****SPAM*****
report_safe 0
trusted_networks 127.0.0.1
required_score 5.0
use_bayes 1
bayes_auto_learn 1
dns_available yes 

If too many messages which are not spam are being tagged as spam, increase "required_score"

Now we need to configure Postfix to use SpamAssassin. Append "-o content_filter=spamassassin" in the /etc/postfix/master.cf file so the first line looks like this:

File: etc/postfix/master.cf
smtp inet n - n - - smtpd -o content_filter=spamassassin

Now at the end of the file add the following (it is all one line):

File: etc/postfix/master.cf
spamassassin unix - n n - - pipe user=nobody argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

[edit] Services

Start up all the services...

/etc/init.d/postfix start /etc/init.d/spamd start /etc/init.d/courier-authlib start /etc/init.d/courier-imapd start /etc/init.d/apache2 start /etc/init.d/named start

You may want to configure these services to start at boot

rc-update add postfix default rc-update add spamd default rc-update add courier-authlib default rc-update add courier-imapd default rc-update add apache2 default rc-update add named default

That's it, you should now have a mail server up and running for your domain. You can access your Squirrelmail installation at http://domain.tld/squirrelmail/

[edit] See also

[edit] External links

Personal tools