Ausgangslage
Ein Kunde hat mit kürzlich danach gefragt, wie ich den Output eines Scripts auf einer Linuxplattform per Mail sauber formatiert versenden kann. Als Beispiel nehmen wir folgedes:
____________________________________________________________________________________________________________________ File System free space on fed22v1.localdomain ____________________________________________________________________________________________________________________ | | | Mb-Total Mb-Free 0% 20% 40% 60% 80% 100% | | / : 17918 16263 #####----+---------+---------+---------+---------+ 10% | | /boot : 476 326 #############------+---------+---------+---------+ 27% | | /dev : 479 479 +--------+---------+---------+---------+---------+ 0% | | /dev/shm : 488 488 +--------+---------+---------+---------+---------+ 0% | | /run : 488 487 +--------+---------+---------+---------+---------+ 1% | | /run/user/0 : 97 97 +--------+---------+---------+---------+---------+ 0% | | /sys/fs/cgroup : 488 488 +--------+---------+---------+---------+---------+ 0% | | /tmp : 488 487 +--------+---------+---------+---------+---------+ 1% | |____________________________________________________________________________________________________________________|
Sende ich den Output direkt per Mail, dann sieht das Mail wie folgt aus:
/root/fsdisc.ksh -s1 | mailx -s "Testmail normale Priorität Text-Format 8bit Encoding" mailaddr@gmail.com
Das Mail ist so nur knapp lesbar, das ist definitiv nicht gewünscht!
Hier muss es doch mehr geben?
Ja, es gibt mehr:
From: root@localhost To: mailaddr@gmail.com Subject: Testmail normale Priorität HTML-Format 8bit Encoding MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit <html> <body> <pre style="font: monospace"> ____________________________________________________________________________________________________________________ File System free space on fed22v1.localdomain ____________________________________________________________________________________________________________________ | | | Mb-Total Mb-Free 0% 20% 40% 60% 80% 100% | | /dev : 479 479 +--------+---------+---------+---------+---------+ 0% | | /dev/shm : 488 488 +--------+---------+---------+---------+---------+ 0% | | /run/user/0 : 97 97 +--------+---------+---------+---------+---------+ 0% | | /sys/fs/cgroup : 488 488 +--------+---------+---------+---------+---------+ 0% | | /run : 488 487 +--------+---------+---------+---------+---------+ 1% | | /tmp : 488 487 +--------+---------+---------+---------+---------+ 1% | | / : 17918 16254 #####----+---------+---------+---------+---------+ 10% | | /boot : 476 326 #############------+---------+---------+---------+ 27% | |____________________________________________________________________________________________________________________| </pre> </body> </html>
Das Mail muss als HTML Mail, mit einem nicht proportionalen Font(monospace) erzeugt werden. Ist der Mailheader mit den richtigen Attributen versehen so sieht das Mail genau so aus wie im Terminalfenster.
Das Resultat kann sich sehen lassen:
Jetzt muss nur noch die möglichkeit geschaffen werden auch die Priorität in dem Mail mitzugeben, damit in einem Mail-Client wie Outlook das Prioritätsflag gesetzt wird.
From: root@localhost To: mailaddr@gmail.com Subject: Testmail hohe Priorität HTML-Format 8bit Encoding MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Disposition: inline X-Priority: 1 (Highest); X-MSMail-Priority: High Content-Transfer-Encoding: 8bit <html> <body> <pre style="font: monospace"> ____________________________________________________________________________________________________________________ File System free space on fed22v1.localdomain ____________________________________________________________________________________________________________________ | | | Mb-Total Mb-Free 0% 20% 40% 60% 80% 100% | | /dev : 479 479 +--------+---------+---------+---------+---------+ 0% | | /dev/shm : 488 488 +--------+---------+---------+---------+---------+ 0% | | /run/user/0 : 97 97 +--------+---------+---------+---------+---------+ 0% | | /sys/fs/cgroup : 488 488 +--------+---------+---------+---------+---------+ 0% | | /run : 488 487 +--------+---------+---------+---------+---------+ 1% | | /tmp : 488 487 +--------+---------+---------+---------+---------+ 1% | | / : 17918 16254 #####----+---------+---------+---------+---------+ 10% | | /boot : 476 326 #############------+---------+---------+---------+ 27% | |____________________________________________________________________________________________________________________| </pre> </body> </html>
Das Ergebnis sieht dann im Outlook so aus:
Es ist mit angaben im Mailheader möglich auch aus Linux gut formatierte Mail zu erzeugen.
Damit wir ein HTML-Mail mit dem Font Monospace erstellen können benötigen wir die folgenden Attribute:
MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit <html> <body> <pre style="font: monospace"> -> Hier kommt der Mailinhalt </pre> </body> </html>
Damit wir die Priorität auf hoch setzen können benötigen wir diese Attribute:
MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Disposition: inline X-Priority: 1 (Highest); X-MSMail-Priority: High Content-Transfer-Encoding: 8bit <html> <body> <pre style="font: monospace"> </pre> </body> </html>
Ja, somit kann ein Script erstellt werden der das Wrapping rund um die Mailheader Attribute durchführt.
Ich hoffe mit diesem Beitrag konnte etwas Licht in die Welt der Mail, Mailheader Attribute gebracht werden.
Cet article Mail mit Format und Priorität aus Linux est apparu en premier sur Blog dbi services.