Send mail with font change

Hi All,
I have a file that contains following entries.
I want to highlight the line that has word as "FAILURE" while sending the email.

File

------------------------------------------------------------

Job Name:       ABC
Start Time:     07/20/2019 07:32:39
End Time:       07/20/2019 07:32:42
Status:         SUCCESS 07/20/2019 07:32:42

------------------------------------------------------------

Job Name:       DEF
Start Time:     07/20/2019 07:32:19
End Time:       07/20/2019 07:32:21
Status:         FAILURE 07/20/2019 07:30:26
Status:         SUCCESS 07/20/2019 07:32:21

------------------------------------------------------------

Job Name:       GHI
Start Time:     07/20/2019 07:30:06
End Time:       07/20/2019 07:30:08
Status:         SUCCESS 07/20/2019 07:30:08

------------------------------------------------------------

I am using following simple method to send mail, but not familiar how to change the font of particular text where error is seen.
Pls help

{
echo "From: "
echo "To:  abc@xyz.com
echo "Subject: Status Report - for jobs -- $DATE"

cat /tmp/report.$DATE
} | /usr/sbin/sendmail -t

Have you considered formatting and sending your email message as an HTML file?

1 Like

Thanks Neo, I am not familiar with HTML tags, a sample would work please.

Here is a rough example:

(
echo "From: ${from}";
echo "To: ${to}";
echo "Subject: ${subject}";
echo "Content-Type: text/html";
echo "";
echo "${message}";
) | sendmail -t

You need for format your messages, for example (example only);

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Your Title</title>
  </head>
  <body>
  <div class="your-css-class">
  Your HTML formatted message
  </div>
 </body>
</html>

A "mail" is basically a (raw) text document, like an ASCII file. You cannot "format" it with markup.

There is the MIME standard that allows mail to contain (several) parts which are not text. This nowadays is regularly used to send mail in HTML format, with embedded pictures and even embedded scripts (like Javascript, ...). This in fact is why mail became so dangerous in the last years: the possibility to send executable code and all sorts of possibly malign parts in a mail along with mail client programs (Outlook foremost) which executes everything sent to it automatically to make life for the user more "comfortable".

Correctly configured mail programs convert every mail from any format (HTML, rich text format, ...) into simple ASCII and will not execute any code at all. True, it won't look as dazzling, but if you have information to get across instead of presentation you will appreciate the riskless and non-dangerous property of this way.

Bottom line: As you need to change the text of your mail anyway (converting it to HTML means adding HTML tags which also changes the text) you should consider simpler ways to let certain lines stand out, i.e.:

------------------------------------------------------------

Job Name:       ABC
Start Time:     07/20/2019 07:32:39
End Time:       07/20/2019 07:32:42
Status:         SUCCESS 07/20/2019 07:32:42

------------------------------------------------------------

Job Name:       DEF
Start Time:     07/20/2019 07:32:19
End Time:       07/20/2019 07:32:21
---> Status:         FAILURE 07/20/2019 07:30:26
Status:         SUCCESS 07/20/2019 07:32:21

------------------------------------------------------------

Job Name:       GHI
Start Time:     07/20/2019 07:30:06
End Time:       07/20/2019 07:30:08
Status:         SUCCESS 07/20/2019 07:30:08

------------------------------------------------------------

Which is simple and does the same - let the important line stand out.

I hope this helps.

bakunin

1 Like