Hallo Leute,
aus aktuellem Anlass (https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1266305) musste ich mir mal wieder selbst eine Mail mit dmesg aus der shell zusenden (hier geht es nicht um Mailempfang!)
Es gibt so viele Ansätze, aber ich habe einen gefunden, der einfach und "straight-forward", ohne Zertifikatgefrickel unter Ubuntu mit vertretbarem Aufwand einzurichten ist und funktioniert! Früher hiess das Program nail, jetzt mailx.
Da es mit Ubuntu 14.04 (Testversion) getestet wurde, denke ich, das ganze ist zukunftssicher 😉
Die Sache verwende ich mit Google und Gmx. Sollte aber für alle gängigen Provider gehen. Ich verwende es auch für meinen eigenen - selbst zeritifizierten - Mailserver.
Was ich zusammengetragen habe, möchte ich mit euch teilen 😉
Gruss und viel Spass beim Mailen.
Aktuelle Version hier: [ENGLISCH] https://wiki.blue-it.org/Bash#Send_the_mail
Getestet in:
Ubuntu 12.04
Ubuntu 14.04
Getestet mit:
google
gmx
Inspired by:
Pakete
1 | sudo apt-get install ca-certificates heirloom-mailx msmtp |
Konfigurationsdateien
Eine Konfigurationsdatei für msmtp:
1 | vim ~/.msmtprc
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # config options: http://msmtp.sourceforge.net/doc/msmtp.html#A-user-configuration-file defaults logfile /tmp/msmtp.log # settings for gmx account gmx auth on host mail.gmx.de port 587 user username@gmx.de from username@gmx.de password PASSHERE tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt # settings for google account gmx auth on host smtp.gmail.com port 587 user username@gmail.com from username@gmail.com password PASSHERE tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt # set default account to account default: gmx |
Und eine Konfigurationsdatei für mailx:
1 | vim ~/.mailrc
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # set smtp for mailx # (default) set from="username@gmx.de" set sendmail="/usr/bin/msmtp" set message-sendmail-extra-arguments="-a gmx" account gmx { set from="username@gmx.de (Your name) send from command line" set sendmail="/usr/bin/msmtp" set message-sendmail-extra-arguments="-a gmx" } account google { set from="username@gmail.com (Your Name) send from command line" set sendmail="/usr/bin/msmtp" set message-sendmail-extra-arguments="-a google" } |
Email versenden
1 2 3 | mailx -A gmx -s "gmx test" username@gmx.de < /tmp/test_email.txt echo "mail text" | mailx -A gmx -s "gmx test" username@gmx.de cat /tmp/test_email.txt | mailx -A gmx -s "gmx test" username@gmx.de |
Attachement hinzufügen
1 | echo "mail text" | mailx -A gmx -a attachment.file -s "gmx test" username@gmx.de |
Die Ausgabe eines Programms senden (heir dmesg):
1 | dmesg | mailx -A gmx -s "$HOSTNAME dmesg" username@gmx.de |
Erläuterungen
-A xxx : Name des acounts ~/.msmtprc AND .mailrc. Wird er weggelassen, dann wird der als default deklarierte verwendet. -s "Text" : Betreff - a datei : Attachment