Mailserver

From EpixStudios

Jump to: navigation, search

Contents

SMTP Server (Postfix)

Main setup

emerge --sync
emerge -av postfix

Edit /etc/postfix/main.cf

myhostname = $host.domain.name
mydomain = $domain.name
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain $mydomain
mynetworks_style = host   # Makes sure the server does not relay messages to users not at this host
home_mailbox = .maildir/
local_destination_concurrency_limit = 2
default_destination_concurrency_limit = 10

Start the Postfix server

/etc/init.d/postfix start

Add it to your default runlevel so it gets started when your computer starts.

rc-update add postfix default

Virtual domains

You can accept mail for other domains and have it directed to a user's account on the machine. This is useful for providing email to customers on different domain names, without having separate machines (much like Apache lets you do with websites). You will usually want a separate user account for each domain user (useradd).

At the bottom of /etc/postfix/main.cf add these two lines. virtual_alias_domains is used to tell Postfix what domains it should accept mail for. virtual_alias_maps specifies where the map file for this will be (we will create this in the next step).

virtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual

Create the file /etc/postfix/virtual and map domain users to local machine users like this example:

info@example.com username
mail@example.com username
postmaster@example.com otherusername
abuse@example.com otherusername

Whenever you make changes to this virtual alias file you must inform Postfix with:

postmap /etc/postfix/virtual

And reload Postfix itself:

postfix reload


Testing/Debugging

Edit /etc/postfix/master.cf if you want verbose logs in /var/log/messages

# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (50)
#
==========================================================================
(Just add the "-v" after the smtpd in the following line)
smtp      inet  n       -       n       -       -       smtpd -v


You can test the server using telnet:

telnet epixstudios.co.uk 25
EHLO epixstudios.co.uk

A list of features supported by Postfix is displayed

MAIL FROM: you@anotherdomain.tld
RCPT TO: username
DATA

Enter text for the email and finish with a single '.' on the last line to send

QUIT


I use a command-line mail reader to check that messages are being delivered to my user account on the server.

emerge -av mutt

On the server:

mutt


After making changes to the config files you need to reload Postfix otherwise the new settings will not be made active.

/etc/init.d/postfix restart

or

postfix reload


Spam & virus filtering (Amavisd-new, Spamassassin, Clam)

emerge -av amavisd-new spamassassin clamav

Insert into the bottom of /etc/postfix/main.cf

content_filter = smtp-amavis:[127.0.0.1]:10024


Configure Amavisd-new - Edit /etc/amavisd.conf

Set which account notification emails should be sent to by setting the variables beginning with 'mailfrom_notify_'.

Set the variable '$spam_quarantine_to' so quarantined mail gets sent to an account.

#$spam_quarantine_to = 'spam-quarantine';
$spam_quarantine_to = "postmaster\@$mydomain";

Set the SpamAssassin threshold levels to qualify as spam and trigger a quarantine (the values in amavisd.conf override the ones set in the SpamAssassin config).

$sa_tag_level_deflt  = 0.0;
$sa_tag2_level_deflt = 5.0;
$sa_kill_level_deflt = 8.0;


Set ClamAV to keep it's database up-to-date

sudo crontab -e
21 3 * * * /usr/bin/freshclam --quiet // Update at 3:21am everyday


Configure SpamAssassin for Bayesian learning - Edit /etc/mail/spamassassin/local.cf

bayes_auto_learn 1
bayes_auto_learn_threshold_nonspam 1
bayes_auto_learn_threshold_spam 14.00

Authentication (Cyrus-sasl)

This will link login resquests to system usernames and passwords

emerge cyrus-sasl
nano -w /etc/sasl2/smtpd.conf
mech_list: PLAIN LOGIN
pwcheck_method: saslauthd
nano -w /etc/conf.d/saslauthd
SASLAUTHD_OPTS="${SASLAUTH_MECH} -a rimap -r"
SASLAUTHD_OPTS="${SASLAUTHD_OPTS} -O localhost"
/etc/init.d/saslauthd start
rc-update add saslauthd default


http://www.gentoo.org/doc/en/virt-mail-howto.xml

http://gentoo-wiki.com/HOWTO_Spam_Filtering_with_Gentoo,_Postfix,_Amavis

Personal tools