# Einrichten Emailversand mit Postfix

Damit auch Emailbenachrichtungen raus gehen, richten wir uns einen Postfix SMTP Server ein.  
Abhängigkeiten installieren

```
apt-get install -y postfix bsd-mailx
```

NunInternet Site auswählen

[![Auswahl_836.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/sLVcoAcNA1KdOCcB-auswahl-836.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/sLVcoAcNA1KdOCcB-auswahl-836.png)

Email Name ausfüllen: checkmk.local.lan

[![Auswahl_833.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/OE76heC3PIVpTs1l-auswahl-833.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/OE76heC3PIVpTs1l-auswahl-833.png)

Nun den Emailempfänger für root eingeben.

[![Auswahl_837.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/begM0vEDZAgKs1KJ-auswahl-837.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/begM0vEDZAgKs1KJ-auswahl-837.png)

weitere zeile, einfach so lassen

[![Auswahl_838.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/DmXa97Xba2nNp7iY-auswahl-838.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/DmXa97Xba2nNp7iY-auswahl-838.png)

bei Synchrone Aktualiseirungen... Nein auswählen

[![Auswahl_839.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/6s1NkljXpWn5JeD5-auswahl-839.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/6s1NkljXpWn5JeD5-auswahl-839.png)

Postfachgröße 0 einfach weiter klicken

[![Auswahl_841.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/LOfKGp4NWmoe80Lj-auswahl-841.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/LOfKGp4NWmoe80Lj-auswahl-841.png)

Zeichen für Adresserweiterung

[![Auswahl_842.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/J4XsRFO4sO1WrGLZ-auswahl-842.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/J4XsRFO4sO1WrGLZ-auswahl-842.png)

Alle auswählen

[![Auswahl_843.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/SgUwaa2WVyGTbtrX-auswahl-843.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/SgUwaa2WVyGTbtrX-auswahl-843.png)

nun die Postfix datei /etc/postfix/main.cf öffnen

```
nano /etc/postfix/main.cf
```

Inhalt unter smtp\_tls session diese 3 Zeilen einfügen

```
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
```

[![Auswahl_834.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/FgbfjgzSJ01h6R2m-auswahl-834.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/FgbfjgzSJ01h6R2m-auswahl-834.png)

Nun noch den relyhost anpassen. Bei mir ist es rs001871.fastrootserver.de

[![Auswahl_835.png](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/scaled-1680-/RBAP3lb1SfX0E6EY-auswahl-835.png)](https://wiki.hacker-net.de/uploads/images/gallery/2022-11/RBAP3lb1SfX0E6EY-auswahl-835.png)

Nun die Password File anlegen

```
nano /etc/postfix/sasl_passwd
```

Inhalt, SMTP Host, Benutzername, Kennwort

```
[rs001871.fastrootserver.de]:587 monitoring@star-module.com *****
```

Nun die Password File eine Postmap draus machen

```
postmap /etc/postfix/sasl_passwd
```

Nun den Postfix-Server neustarten

```
service postfix restart
```

Testemail senden

```
echo "Dies ist eine Test E-Mail vom checkmk-Server" | mailx -s "Test" <ihre_notification_e-mail-adresse@gmail.com>
```

```
in der /var/log/mail.log kann man das ergebnis sehen.
```

hier ein Fehler beispiel, bei der Authentifizierung. Ganz am ende steht authetication failed. So weiß man, okay Kennwort falsch.

```
Nov 29 11:38:45 checkmk postfix/postfix-script[26039]: starting the Postfix mail system
Nov 29 11:38:45 checkmk postfix/master[26041]: daemon started -- version 3.5.13, configuration /etc/postfix
Nov 29 11:40:53 checkmk postfix/postfix-script[26644]: stopping the Postfix mail system
Nov 29 11:40:53 checkmk postfix/master[26041]: terminating on signal 15
Nov 29 11:40:54 checkmk postfix/postfix-script[27198]: starting the Postfix mail system
Nov 29 11:40:54 checkmk postfix/master[27200]: daemon started -- version 3.5.13, configuration /etc/postfix
Nov 29 11:41:10 checkmk postfix/pickup[27201]: A9F0D2075B: uid=0 from=<root>
Nov 29 11:41:10 checkmk postfix/cleanup[27249]: A9F0D2075B: message-id=<20221129104110.A9F0D2075B@checkmk.local.lan>
Nov 29 11:41:10 checkmk postfix/qmgr[27202]: A9F0D2075B: from=<root@checkmk.local.lan>, size=440, nrcpt=1 (queue active)
Nov 29 11:41:10 checkmk postfix/smtp[27251]: A9F0D2075B: to=<bonkersdeluxe@gmail.com>, relay=rs001871.fastrootserver.de[213.202.247.147]:25, delay=0.24, delays=0.02/0.02/0.21/0, dsn=4.7.8, status=deferred (SASL authentication failed; server rs001871.fastrootserver.de[213.202.247.147] said: 535 5.7.8 Error: authentication failed: authentication failure)

```

So sähe ein erfolgreicher Versand aus

```
Jan 20 10:22:03 checkmk postfix/pickup[603605]: 317CB20BB6: uid=0 from=<root>
Jan 20 10:22:03 checkmk postfix/cleanup[606550]: 317CB20BB6: message-id=<20230120092203.317CB20BB6@checkmk.local.lan>
Jan 20 10:22:03 checkmk postfix/qmgr[1102]: 317CB20BB6: from=<root@checkmk.local.lan>, size=443, nrcpt=1 (queue active)
Jan 20 10:22:03 checkmk postfix/smtp[606552]: 317CB20BB6: to=<monitoring@star-module.com>, relay=rs001871.fastrootserver.de[213.202.247.147]:25, delay=0.36, delays=0.02/0.01/0.19/0.14, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 65D0A18806E2)
Jan 20 10:22:03 checkmk postfix/qmgr[1102]: 317CB20BB6: removed

```