Difference between revisions of "Mail Server"

From Briki
Jump to: navigation, search
(Postfix)
(Configuring SpamAssassin as a content filter)
Line 20: Line 20:
 
== Postfix ==
 
== Postfix ==
 
=== Configuring SpamAssassin as a content filter ===
 
=== Configuring SpamAssassin as a content filter ===
See: http://www.debuntu.org/postfix-and-pamassassin-how-to-filter-spam
+
Adapted from: http://www.debuntu.org/postfix-and-pamassassin-how-to-filter-spam
  
 
* <pre>wajig install spamassassin spamc</pre>
 
* <pre>wajig install spamassassin spamc</pre>
Line 40: Line 40:
 
* Edit '''/etc/init.d/spamassassin''':
 
* Edit '''/etc/init.d/spamassassin''':
 
** Add ''USER=spamd'' to the default variables block
 
** Add ''USER=spamd'' to the default variables block
** Add ''--chuid $USER'' to the start cmd
+
** Add ''--chuid $USER'' to the start and restart cmds
  
 
* Add to /etc/postfix/master.cf:
 
* Add to /etc/postfix/master.cf:

Revision as of 13:31, 4 March 2008

General

See https://help.ubuntu.com/community/MailServer for an introduction to MTA/Spamassassin

MTA 
Mail Transport Agent (generally SMTP)
MDA 
Mail Delivery Agent
MUA 
Mail User Agent (generally POP3 or IMAP)

Briefly, the workflow for mail delivery is:

[Internet] -> postfix (MTA) -> SpamAssassin -> postfix (MTA) -> procmail (MDA) -> $HOME/Maildir

and for mail viewing:

$HOME/Maildir -> Courier (IMAP MUA) -> Thunderbird/Outlook

or

$HOME/Maildir -> Mutt/Pine

Postfix

Configuring SpamAssassin as a content filter

Adapted from: http://www.debuntu.org/postfix-and-pamassassin-how-to-filter-spam

  • wajig install spamassassin spamc
  • Create a spamd user:
sudo adduser --system --group --home /var/lib/spamassassin userid
  • Create /var/run/spamassassin and /var/lib/spamassassin, owned by spamd:spamd
  • Add/change the following lines in /etc/default/spamassassin:
ENABLED=1
OPTIONS="--create-prefs --max-children 5 --port 1783 -s /var/log/spamassassin/spamd.log"
PIDFILE="/var/run/spamassassin/spamd.pid"
  • Edit /etc/init.d/spamassassin:
    • Add USER=spamd to the default variables block
    • Add --chuid $USER to the start and restart cmds
  • Add to /etc/postfix/master.cf:
spamassassin unix -     n       n       -       -       pipe
  user=spamd argv=/usr/bin/spamc -f -p 1783 -e
  /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Again in /etc/postfix/master.cf, change the smtp content filters to:

smtp      inet  n       -       -       -       -       smtpd
        -o content_filter=spamassassin

Configuring postfix delivery method

The following config should be placed within /etc/postfix/main.cf

To use postfix's builtin MDA with mbox format (/var/spool/mail/$USER)

# Use mbox mailboxes (the default)
home_mailbox = mbox

Ensure no mailbox_command is specified

To use postfix's builtin MDA with Maildir formar ($HOME/Maildir/*)

# Use Maildir style mailboxes
home_mailbox = Maildir/

Ensure no mailbox_command is specified

To use procmail as external MDA

# Use procmail
mailbox_command = /usr/bin/procmail

Ensure no home_mailbox is specified

=== Configuring mail for an unknown destination to route to a specific user:

# Redirect unknown users to andrew
luser_relay = andrew
local_recipient_maps =

Hardening postfix

Add the following to /etc/postfix/main.cf:

## Restrictions
# Require a valid handshake, with the sender announcing its name
smtpd_helo_required = yes
# Require the sending server to have an A or MX record in DNS
#smtpd_sender_restrictions = hash:/etc/postfix/sender_access,reject_unknown_sender_domain
smtpd_sender_restrictions = reject_unknown_sender_domain
# Require the recipient to be a configured destination, unless from mynetworks (NB. This is default, anyway)
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

Emptying deferred queue

To attempt redelivery:

sudo postfix flush

To simply delete all deferred mails:

sudo postsuper -d ALL

Testing postfix header_checks

postmap -q - regexp:/etc/postfix/header_checks < /tmp/testmessage

SpamAssassin

Pyzor

Meaning of output like:

82.94.255.100:24441     (200, 'OK')     1206    0
82.94.255.100
24441
Pyzor server
(200, 'OK')
HTTP response from server
1206
Number of spam matches for tested message
0
Number of whitelist (definite non-spam) matches for tested message

Pyzor will return 0 (identifying the message as spam) only if number of spam matches > 0 and number of whitelist matches = 0.

Roundcube

Fixing blank screen on IMAPS login with "Call to undefined function mcrypt_module_open" error in /var/log/roundcube/errors

  • Install php-mcrypt