Postfix

aus www.kruedewagen.de, Homepage von Ralf und Judith Krüdewagen (Kruedewagen)
Zur Navigation springen Zur Suche springen

Postfix ist ein Open-Source SMTP Email-Server (MTA).

SpamAssassin Integration

Siehe Anleitung hier.

Zusammenfassung der Schritte

  • Spamassassins von openSUSE verwenden
  • User und Gruppe filter angelegt mit $HOME=/home/filter
  • spool Verzeichnis anlegen
mkdir /var/spool/filter
chown -R filter.filter /var/spool/filter
  • Datei /home/filter/sc/filter.sh angelegt mit 755 Permissions und filter:filter Owner. Dateininhalt:
#!/bin/sh
INSPECT_DIR=/var/spool/filter
SENDMAIL=/usr/sbin/sendmail
SPAMASSASSIN=/usr/bin/spamc
# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
# Clean up when done or when aborting.
trap "rm -f in.$$; rm -f out.$$" 0 1 2 3 15
# Parameter for $SPAMASSASSIN
#  -P   Pipe message, don't deliver
#  -x   Disable user config files
#  -a   Use auto-whitelists
cat | $SPAMASSASSIN  > out.$$ || { echo Message content rejected; exit $EX_UNAVAILABLE; }
$SENDMAIL -i "$@" < out.$$
exit $?
  • /etc/mail/spamassassin/local.cf angelegt mit Inhalt:
required_score          4.0
rewrite_header Subject  ****SPAM(_SCORE_)****
report_safe             1
use_bayes               1
skip_rbl_checks         0
use_razor2              1
use_dcc                 1
use_pyzor               1
ok_locales              en
bayes_auto_learn        1
# SUSE default
ifplugin Mail::SpamAssassin::Plugin::URIDNSBL
uridnsbl_skip_domain suse.de opensuse.org suse.com suse.org
uridnsbl_skip_domain novell.com novell.org novell.ru novell.de novell.hu novell.co.uk
endif   # Mail::SpamAssassin::Plugin::URIDNSBL
  • spamd starten und in runlevel setzen:
/etc/init.d/spamd start
insserv spamd
  • Postfix master.cf anpassen:
smtp      inet  n       -       n       -       -       smtpd -o content_filter=filter:
...
...
# SPAMASSASIN
filter    unix  -       n       n       -       -       pipe
  user=filter argv=/home/filter/sc/filter.sh -f ${sender} -- ${recipient}
  • Auto-Update der Bayes-Filter in /etc/cron.daily/spamassassins-update, siehe SpamAssassin.
  • Spamassassin-Installation überprüfen:
spamassassin -D --lint
require "fileinto";
if exists "X-Spam-Flag" {
  fileinto "SPAM";
}

Unitymedia/ISH Konfiguration

Die folgende Konfiguration dient zum Senden aller ausgehenden Mails über den SMTP-Relay von Unitymedia. Dabei wird eine Authentifizierung (SASL) des Clients vorgenommen. Die Verbindung wird zudem per TLS verschlüsselt.

Siehe auch mein Posting bei Fedoraforum.de.

Mit TLS und CRAM-MD5

Einträge in main.cf:

relayhost = smtp.ish.de
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain,login,cram-md5
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/postfix/cacert_class3.crt
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache

Es geht auch so nur mit cram-md5:

smtp_sasl_mechanism_filter = cram-md5

Eintrag in /etc/postfix/sasl_passwd:

smtp.ish.de     user:password

Und dann noch /etc/postfix/sasl_passwd.db erzeugen:

postmap /etc/postfix/sasl_passwd

Siehe auch [1].

Ohne TLS , PLAIN/LOGIN

Einträge in main.cf:

relayhost = smtp.ish.de
smtp_sasl_auth_enable = yes
smtp_use_tls = no
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain,login,cram-md5

SMTP Auth

SMTP Auth dient zum Authentifizieren von Nutzern beim Versenden von Mails per SMTP über den Server.

Dovecot /usr/local/etc/dovecot/conf.d/10-master.conf:

service auth {
  unix_listener auth-userdb {
    #mode = 0600
    #user = 
    #group = 
  }

  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }

  # Auth process is run as this user.
  #user = $default_internal_user
}

Postfix main.cf mit saslauthd:

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname

Postfix main.cf mit Dovecot:

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname

Port 587

Port 587 kann zum Ausliefern von Mails vom Client zum Server benutzt werden. Dies ist besonders dann von Vorteil, wenn STARTTLS auf Port 25 durch vergurkte Firewalls blockiert wird [1] mit dem folgenden Symptom:

# telnet mail.example.com 25
Trying 176.198.196.53...
Connected to mail.example.com.
Escape character is '^]'.
220 *********************************
EHLO 1
250-mail.example.com
250-PIPELINING
250-SIZE 40960000
250-VRFY
250-ETRN
250-XXXXXXXA
250-AUTH PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

Statt 250-XXXXXXXA sollte dort 250-STARTTLS stehen.

Einstellung in master.cf:

submission inet n      -       n       -       -       smtpd
        -o smtpd_etrn_restrictions=reject
        -o smtpd_client_restrictions=permit_sasl_authenticated,reject

TLS

Server

Server-Konfiguration in main.cf:

smtpd_use_tls = yes

#smtpd_tls_security_level = encrypt
smtpd_tls_security_level = may

smtpd_tls_auth_only = no

smtpd_tls_CAfile = /etc/postfix/cacert_class3.crt
smtpd_tls_cert_file = /etc/apache2/ssl.crt/server.crt
smtpd_tls_key_file = /etc/apache2/ssl.key/server.key
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_tls_session_cache
tls_random_source = dev:/dev/urandom

Zusätzliche Einstellungen für optimale Cipher (Stichwort Diffie-Hellman und Perfect Forward Secrecy):

smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
# the server has prio when choosing cipher, client are forced to use best mode
tls_preempt_cipherlist = yes
# 2048 key instead of 1024 created
smtpd_tls_dh1024_param_file = /etc/postfix/dh_2048.pem
smtpd_tls_dh512_param_file = /etc/postfix/dh_512.pem
smtpd_tls_eecdh_grade = strong

Weblinks:

Client

Client-Konfiguration siehe am Beispiel Unitymedia oben.

Testen

  • Verbindungstest
openssl s_client -starttls smtp -connect mymailhost.de:25
  • Postfix-Log
Anonymous TLS connection established from xxx: TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)

Weblinks

IPv6

Siehe IPv6#Postfix.

Logdateien

pflogsumm.pl

Beispiele:

pflogsumm -d yesterday /var/log/mail
pflogsumm -d today /var/log/mail

Beispiele mit archivierten Dateien:

(xzcat `ls -rt /var/log/mail-2014*`; cat /var/log/mail) | pflogsumm -d yesterday

oder besser nur die archivierten Logdateien des letzten, des aktuellen Monats und die aktuelle Logdatei einlesen (keine Überschneidung am Monatsende mit logrotate)

(xzcat $(ls -rt /var/log/mail-$(date --date="-1 month" +"%Y%m")*); xzcat $(ls -rt /var/log/mail-$(date +"%Y%m")*); cat /var/log/mail) | pflogsumm -d yesterday

als cronjob % escapen und per Mail verschicken:

01 0 * * *     root (xzcat $(ls -rt /var/log/mail-$(date --date="-1 month" +"\%Y\%m")*); xzcat $(ls -rt /var/log/mail-$(date +"\%Y\%m")*); cat /var/log/mail) | /usr/local/bin/pflogsumm -d yesterday | mail -s "mail stats from $(date --date='-1 day' +'\%d.\%m.\%Y')" you@example.com

Hinweise:

  • Ohne "-d" werden alle Einträge ausgewertet. Um bestimmte Zeiten (z.B. eine Woche) zu filtern mit "grep" vorfiltern.

Andere

Siehe auch

Weblinks