0

Below is an sample file. i need to send mail with file contents as message body. i tried so many ways like printf, cat, piping to mail command but all are truncating the spaces. Format is different. Please provide suggestion. how i can get an email as looks like in file.

---------------------------------------------
Description                       |Date|Count
Audit Entries                     |07-DEC-15|5
COL File                          |07-DEC-15|1
-----------------------------------------------
srinath
  • 91
  • 1
  • 8
  • Could you [send the mail body as HTML](http://stackoverflow.com/questions/2591755/how-send-html-mail-using-linux-command-line)? – ewan.chalmers Dec 07 '15 at 10:18
  • show how you are sending the mail please. – Erik Nyquist Dec 07 '15 at 10:23
  • whats the command you use to send mail ? – Saril Sudhakaran Dec 07 '15 at 10:34
  • I tried few ways.. like #mesasge="$(cat "$EMAIL_MESSAGE")" #printf "%s" "$mesasge" | /bin/mail -s "$SUBJECT" "$EMAIL" cat "$EMAIL_MESSAGE" | /bin/mail -E -s "$SUBJECT" "$EMAIL" – srinath Dec 07 '15 at 10:39
  • @sudocode, i dont know about HTML. i like to receive an email to check in my outlook. no attachements. i need in message body as text messages. – srinath Dec 07 '15 at 10:42
  • Are you sure the content is actually being changed? If Outlook displays the message in a variable-width font (as it probably does by default, even for plain text messages) then your columns will be misaligned even though the number of spaces is correct. Cut and paste the message from Outlook into Notepad or some other plain text editor to see how it looks there. –  Dec 07 '15 at 11:45
  • @Wumpus, you are correct. Outlook is displaying wrongly. when i copy paste to notepad. spaces are coming correctly. So what shall i do now? – srinath Dec 07 '15 at 14:36

2 Answers2

0

I expect that the spaces are getting truncated in the shell, as shown in this example:

$ cat msg.txt
---------------------------------------------
Description                       |Date|Count
Audit Entries                     |07-DEC-15|5
COL File                          |07-DEC-15|1
-----------------------------------------------
$
$
$ message=$(cat msg.txt)

Truncated:

$ echo $message
--------------------------------------------- Description |Date|Count Audit Entries |07-DEC-15|5 COL File |07-DEC-15|1 -----------------------------------------------

Not truncated:

$ echo "$message"
---------------------------------------------
Description                       |Date|Count
Audit Entries                     |07-DEC-15|5
COL File                          |07-DEC-15|1
-----------------------------------------------
$

I think you could simplify things by outputting your message content to file and then using that as the input to your mail command, like this

mail -s "$SUBJECT" "$EMAIL" < the_file
ewan.chalmers
  • 16,145
  • 43
  • 60
0

If you want to send a message containing columns of text, and have the columns appear correctly aligned in Outlook, you have to either change your Outlook settings or send HTML.

In Outlook 2013 I found the plain text font configuration item this way:

  1. File menu
  2. Options menu
  3. Mail tab
  4. Stationery and Fonts button
  5. Personal Stationery tab
  6. Font button under "Composing and reading plain text messages" heading
  7. Under the "Font" heading (not the "Asian text font" heading above it!) is the selector. Choose Lucida Console or some other fixed-width font.
  • i just googled and got the answer. But you are super fast than me. :) https://social.technet.microsoft.com/Forums/office/en-US/6a354c78-64d8-4b68-9651-0f1d33c950ac/outlook-2010-plain-text-not-lining-up – srinath Dec 07 '15 at 14:56