Grundkonfiguration Sendmail

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Sendmail-Konfiguration

Sendmail ist einer der ältesten und am weitesten verbreiteten Mail Transfer Agents (MTA). Aufgrund seiner komplexen Konfiguration wird es oft durch modernere MTAs wie Postfix oder Exim ersetzt, aber es ist weiterhin in vielen Unix- und Linux-Systemen verfügbar.

Vorbereitungen

  • mkdir -p /etc/skel/Maildir/{cur,new,tmp}

Installation

  • apt-get install sendmail sendmail-bin mailutils

Grundkonfiguration

Sendmail verwendet eine Makro-Konfigurationsdatei (`sendmail.mc`), aus der die eigentliche Konfigurationsdatei (`sendmail.cf`) generiert wird.

  • vi /etc/mail/sendmail.mc
define(`SMART_HOST', `smtp.example.com')dnl
FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl

Nach Änderungen die Konfiguration neu generieren:

  • m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Maildir-Format aktivieren

  • vi /etc/mail/sendmail.mc
define(`MAILER_LOCAL', `maildir')dnl

Wichtige Sendmail-Kommandos

  • systemctl status sendmail
  • systemctl start sendmail
  • systemctl stop sendmail
  • systemctl reload sendmail
  • sendmail -bp # Zeigt die Warteschlange
  • sendmail -q # Erzwingt das Senden der Warteschlange

Logging

  • tail -f /var/log/mail.log
Feb 04 13:20:55 mail sendmail[1234]: 1abcdE-0001XY-Qd: from=user@example.com, size=512, nrcpts=1, msgid=<20250204132055@example.com>, relay=client.example.com [192.168.244.1]
Feb 04 13:20:55 mail sendmail[1234]: 1abcdE-0001XY-Qd: to=recipient@example.com, delay=00:00:01, stat=Sent

Installation von Mailutils

  • apt-get install mailutils

Lokales Lesen von Mails

mario@mail:~$ mail
"/var/mail/mario": 5 messages 5 unread
...

Authentifizierung mit SASL

Sendmail kann SASL für SMTP-Authentifizierung nutzen.

Dovecot für SASL konfigurieren

  • vi /etc/dovecot/conf.d/10-master.conf
service auth {
   unix_listener /var/spool/sendmail/auth {
      mode = 0660
      user = smmsp
      group = smmsp
   }
}
  • vi /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login

Sendmail-Konfiguration für SASL

  • vi /etc/mail/sendmail.mc
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl

Nach Änderungen die Konfiguration neu generieren:

  • m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Neustart der Dienste

  • systemctl restart sendmail
  • systemctl restart dovecot

Verschlüsselung mit TLS/SSL

SSL-Zertifikate hinterlegen

  • mkdir /etc/mail/ssl
  • cp /root/xin-ca.crt /etc/mail/ssl
  • cp /root/xin-ca-mail.example.com.crt /etc/mail/ssl
  • cp /root/xin-ca-mail.example.com.key /etc/mail/ssl

Sendmail TLS-Konfiguration

  • vi /etc/mail/sendmail.mc
define(`confCACERT_PATH', `/etc/mail/ssl')dnl
define(`confCACERT', `/etc/mail/ssl/xin-ca.crt')dnl
define(`confSERVER_CERT', `/etc/mail/ssl/xin-ca-mail.example.com.crt')dnl
define(`confSERVER_KEY', `/etc/mail/ssl/xin-ca-mail.example.com.key')dnl
define(`confCLIENT_CERT', `/etc/mail/ssl/xin-ca-mail.example.com.crt')dnl
define(`confCLIENT_KEY', `/etc/mail/ssl/xin-ca-mail.example.com.key')dnl

Nach Änderungen die Konfiguration neu generieren:

  • m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Sendmail neu starten

  • systemctl restart sendmail