Mailserver

22 April 2008

Aufgesetzt wird ein Postfix Server mit Dovecot, Procmail, Spamassassin und Squirrel.
Zunächst sollten alle Programme installiert sein was sich mit Hilfe von Yum schnell realisieren läßt. Damit Squirrel auch läuft brauchen wir den Apache und sollte dieser auch verschlüsseln “mod_ssl” nicht vergessen. Für Postfix benötigen wir noch die “cyrus-sasl” Packete zwecks absicherung.

Zunächst konfigurieren wir den Postfix:

# alternatives --config mta

dann kommt

There are 2 programs which provide "mta".
Selection Command
-----------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
Enter to keep the default[*], or type selection number:

Postfix anwählen

main.cf

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = my.hostname
mydomain = my.domain
#myorigin = $myhostname
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.4.5/samples
readme_directory = /usr/share/doc/postfix-2.4.5/README_FILES
#Procmail und Maildir
home_mailbox = .INBOX/
mailbox_command = /usr/bin/procmail /home/$USER/.procmailrc
#Große Mails
message_size_limit = 80000000
mailbox_size_limit = 8000000000000
queue_minfree = 200000000
#remotelogin
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes

Dovecot:

#protocols = imap imaps pop3 pop3s
protocols = imap imaps
## Mailbox locations and namespaces
# There are a few special variables you can use, eg.:
#
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if there's no domain
# %h - home directory
# mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
mail_location = maildir:/home/%u/.INBOX
mechanisms = plain
user = root

Procmail: procmail.rc

SHELL=/bin/sh
LOGFILE=/home/patrick/ownmail.log
MAILDIR=/home/patrick/.INBOX/
#LOGABSTRACT="all"
#VERBOSE="on"
#Spamassassin1 übergibt alle Nachrichten größer 150000 Byte an Spamassassin
:0fw
* <150000
| spamassassin
#Spamassassin2 verschiebt in Spamordner und markiert als gelesen
:0
* ^X-Spam-Status: Yes
{
foldername=Spam
:0c
.$foldername/ # stores in .$foldername/new/
:0
* LASTFOLDER ?? /\/[^/]+$
{ tail=$MATCH }
TRAP="mv $LASTFOLDER .$foldername/cur/$tail:2,S"
HOST
}
# Nachrichten mit SPAM-Score >= 7 löschen
:0 w
* ^X-Spam-Score:.*\(\*\*\*\*\*\*\*
/dev/null
#Re's Putzen:
:0 fh
* ^Subject:[ ]*(Re:\s*|AW:\s*|SW:\s*|WG:\s*|HW:\s*|WE:\s*|Antwort:\s*)+
| perl -pe 's/^Subject:\s+(?:Re:\s*|AW:\s*|SW:\s*|WG:\s*|HW:\s*|WE:\s*|Antwort:\s*)+(.*)/Subject: Re: $1/i;'
#und
:0 fhw
* Subject:[ \t]*(aw|tr|we):
| sed -e 's/^Subject:[ \t]*\(Aw\|Tr\):/Subject: Re:/i'

# Regel
:0 w
* ^Subject:.*Betreff
.Zielordner/
# Absender
:0w
* ^From:.*Absender
.Absender/
# zu guter letzt
:0
*
/home/USER/.INBOX/

Spamassassin:

zwei Cronjobs mit:

sa-learn --spam /home/pl/.INBOX/.Spam/cur
und
sa-learn --ham /home/pl/.INBOX/.nospam/cur

Squirrel:


$org_name = "Name";
$org_logo = SM_PATH . 'images/sm_logo.png';
$org_logo_width = '308';
$org_logo_height = '111';
$org_title = "SquirrelMail $version";
$provider_name = 'SquirrelMail';
$motd = "";
$squirrelmail_default_language = 'de_DE';
$default_charset = 'utf-8';
$lossy_encoding = false;
$domain = 'Domain.Name';
$imapServerAddress = 'localhost';
$imapPort = 143;
$useSendmail = true;
$smtpServerAddress = 'localhost';
$smtpPort = 25;
$sendmail_path = '/usr/sbin/sendmail';
$sendmail_args = '-i -t';
$pop_before_smtp = false;
$imap_server_type = 'courier';
$invert_time = false;
$optional_delimiter = '.';
$encode_header_key = '';
$default_folder_prefix = 'INBOX';
$trash_folder = 'Trash';
$sent_folder = 'Sent';
$draft_folder = 'Drafts';
$default_move_to_trash = true;
$default_move_to_sent = true;
$default_save_as_draft = true;
$show_prefix_option = true;
$list_special_folders_first = true;
$use_special_folder_color = true;
$auto_expunge = true;
$default_sub_of_inbox = false;
$show_contain_subfolders_option = true;
$default_unseen_notify = 2;
$default_unseen_type = 1;
$auto_create_special = true;
$delete_folder = false;
$noselect_fix_enable = false;

Relay

Sollte der Server keine einen Relayserver zum ausliefern benötigen müssen noch folgende Einträge in die main.cf


##################################
#SMTP Auth - fuer ausgehende Verbindungen - fuer andere SMTP-Server
#SMTP mit SASL-Authentification verwenden
smtp_sasl_auth_enable = yes
#Die Passöwrter stehen in der Datei /etc/postfix/smtp_auth
smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth
#Zusatz-Optionen: Keine anonyme-Anmeldung verwenden
smtp_sasl_security_options = noanonymous
#Der Relayhost (der Server der unsere Emails annehmen soll)
relayhost = nadeinrelayhost

smtp-auth mit folgendem Inhalt anlegen:

nadeinrelayhost benutzername:passwort

anschließend:

# postmap /etc/postfix/smtp_auth

Vertig