[Howto] openSUSE Systemmails über bestehendes E-Mail Konto (GMX) versenden

In diesem Artikel möchte ich kurz beschreiben, wie es auf einem frisch aufgesetzten openSUSE Server (getestet mit 10.3 und aktuell mit 11.1 und 11.2) möglich ist, E-Mails über einen bestehenden E-Mail Account bei einem Provider wie GMX zu versenden. Dazu ist es nicht notwendig, dass der Server eine feste IP oder ähnliches hat. Ganz normaler DSL Zugang genügt.

servermail

Wie sind die einzelnen Schritte (Kurzform)?

  1. Einige Konfigurationsdateien editieren
  2. Die Konfigurationsdateien in eine Datenbank umwandeln
  3. Ein Skript erstellen, welches eine E-Mail versendet
  4. Skript per Cronjob ausführen lassen – Post vom Server ;)

Zuerst wird die wichtigste Datei editiert: /etc/postfix/main.cf

inet_protocols = all
biff = no
mail_spool_directory = /var/mail
canonical_maps = hash:/etc/postfix/canonical
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_alias_domains = hash:/etc/postfix/virtual
relocated_maps = hash:/etc/postfix/relocated
transport_maps = hash:/etc/postfix/transport
sender_canonical_maps = hash:/etc/postfix/sender_canonical
masquerade_exceptions = root
masquerade_classes = envelope_sender, header_sender, header_recipient
myhostname = localhost
delay_warning_time = 1h
message_strip_characters = \0
program_directory = /usr/lib/postfix
inet_interfaces = localhost
masquerade_domains =
mydestination = $myhostname
defer_transports =
mynetworks_style = subnet
disable_dns_lookups = no
mailbox_command =
mailbox_transport =
strict_8bitmime = no
disable_mime_output_conversion = no
smtpd_sender_restrictions = hash:/etc/postfix/access
smtpd_client_restrictions =
smtpd_helo_required = no
smtp_helo_name = localhost
smtpd_helo_restrictions =
strict_rfc821_envelopes = no
smtpd_recipient_restrictions = permit_mynetworks,reject_unauth_destination
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_auth_enable = no
smtp_sasl_security_options = noanonymous
smtpd_use_tls = no
smtp_use_tls = no
alias_maps = hash:/etc/aliases
mailbox_size_limit = 0
message_size_limit = 10240000
inet_protocols = all
biff = no
mail_spool_directory = /var/mail
canonical_maps = hash:/etc/postfix/canonical
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_alias_domains = hash:/etc/postfix/virtual
relocated_maps = hash:/etc/postfix/relocated
transport_maps = hash:/etc/postfix/transport
sender_canonical_maps = hash:/etc/postfix/sender_canonical
masquerade_exceptions = root
masquerade_classes = envelope_sender, header_sender, header_recipient
myhostname = localhost
delay_warning_time = 1h
message_strip_characters = \0
program_directory = /usr/lib/postfix
inet_interfaces = localhost
masquerade_domains =
mydestination = $myhostname
defer_transports =
mynetworks_style = subnet
disable_dns_lookups = no
mailbox_command =
mailbox_transport =
strict_8bitmime = no
disable_mime_output_conversion = no
smtpd_sender_restrictions = hash:/etc/postfix/access
smtpd_client_restrictions =
smtpd_helo_required = no
smtp_helo_name = localhost
smtpd_helo_restrictions =
strict_rfc821_envelopes = no
smtpd_recipient_restrictions = permit_mynetworks,reject_unauth_destination
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_auth_enable = no
smtp_sasl_security_options = noanonymous
smtpd_use_tls = no
smtp_use_tls = no
alias_maps = hash:/etc/aliases
mailbox_size_limit = 0
message_size_limit = 10240000

Jetzt die Datei /etc/postfix/sasl_passwd editieren:

[mail.gmx.net]:25 deine.email@gmx.de:DEIN_PASSWORT

Dann noch das Mapping der User in /etc/postfix/canonical

root deine.email@gmx.de
root@localhost deine.email@gmx.de
root@rechnername deine.email@gmx.de

Diese beiden Dateien müssen in eine DB umgewandelt werden mittels

# postmap /etc/postfix/sasl_passwd

und

# postmap /etc/postfix/canonical

Falls man logs versenden will, kann man noch die /etc/aliases anpassen um die jeweiligen Benutzer auf root zu mappen.

Das Shellskript email.sh

Mit den jetzigen Einstellungen ist es bereits möglich eine E-Mail von der Kommandozeile zu verschicken. Da das natürlich niemand machen will, hab ich hier noch ein Shellskript für euch (in email.sh umbenennen und ausführbar machen mittels chmod +x email.sh), was ich mir mal geschrieben habe. Zu dem Skript gehört noch eine Textdatei mit allen Empfängern (einer pro Zeile), die im Header des Skripts angegeben wird. (Skript muss noch auf euch angepasst werden)

Shellskript als Cronjob eintragen in /etc/crontab (z.B. jeden Tag um 10:00 Uhr)

1       10      *       *       *       root /root/email.sh > /dev/null

Das wars. Falls irgendwas nicht klappt, schreibt mich an ;)

Linux ist sexy! -- by Pinguinblog.de