Skip to content

Mail mit Format und Priorität aus Linux

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 folgendes:

  ____________________________________________________________________________________________________________________
                                                                                                                     
                                  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" [email protected]

2015-12-10_15h18_27

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: [email protected]
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:

2015-12-10_15h44_05

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: [email protected]
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:

2015-12-10_15h59_14

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.

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Oracle Team

Oracle Team

Posts published under the Oracle Team account are collective contributions by the dbi services Oracle consultants. The practice covers the full Oracle Database lifecycle: architecture, migration and upgrade, high availability with RAC and Data Guard, backup and recovery, performance tuning, and engineered systems such as Oracle Database Appliance and Exadata. The team holds Oracle certifications up to Certified Master level and operates customer platforms under service level agreements.View Author posts

1,009 posts since December 2010

Most read in Operating System

The Operating System posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *