'How to use a typesetting content to send mail on Linux?

I want to send a mail which includes a table on linux. To type cat command, the content as below:

enter image description here

But when I use cat $REPORT | mail -s "$MAIL_TITLE" $MAIL_TO The content in the mail will be as below:

[2]

Is it possible to fix that? Thx



Solution 1:[1]

Your terminal is using monospace font that has same width of each character including spaces.

To make your email looks same way you need to

  • define the content font to use one of the monospace fonts

or

  • switch your email client to use the monospace font as default.

Monospace font

Edit

To your example you may just wrap the output into the <div style="font-family: monospace;">...</div> that will force it to be using the monospace and the formatting will looks much better

Possible solution

Is to prepare the output using html div with monospace font family, so the email client will use any kind of monospace that is available in its environment:

echo "<div style='font-family: monospace;'>\n" > monospacemail.txt 
echo $REPORT >> monospacemail.txt 
echo '</div>'  >> monospacemail.txt 
cat monospacemail.txt | mail -s "$MAIL_TITLE"' $MAIL_TO

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1