1

First time posting here.
I have the following file and contents:

linux$ cat file.txt    
line 1
line 2
line 3
line 4

I have the following code:

Output=$(cat file.txt)
echo "$Output" | mail -s "[Test]" -a test.txt host@domain.com

I send the file itself as attachment for debugging purpose. The problem I encounter is that the email body containing the output of 'cat file.txt' looks like this:

line 1
line 2 line
3 line 4

The attached file contains a correctly formatted output of 'cat file.txt', no characters, newlines, spaces are added or removed.

What might be causing this? Appreciate your help!

Spitfire86
  • 13
  • 3
  • Do you have the same problem if you read from `file.txt` directly? I.e., `mail -s "[Test]" -a test.txt host@domain.com < file.txt` – chepner Jan 27 '16 at 15:54
  • 1
    What are you using to read the email? Some email programs like Outlook have an option to "Remove extra line breaks in plain text messages" which can mess with formatting. – Mr. Llama Jan 27 '16 at 16:09

1 Answers1

-1

I would think you probably need to specify in which format your email content should be sending out.

UTF-8 is great option since it's world wide almost.

This might be helpful:

cat file.txt | mail -s '$(echo -e "Test\nContent-Type: text/html")' -a test.txt host@domain.com

or with charset

cat file.txt | mail -s '$(echo -e "Test\nContent-Type: text/html; charset="us-ascii")' -a test.txt host@domain.com

or without UNIX pipeline

mail -a 'Content-type: text/plain; charset="us-ascii"' foo@bar.com < file.txt

More info can be found here.

It really depends on what version of your mail.

Hope this could be helpful

Community
  • 1
  • 1
dotslash
  • 387
  • 5
  • 13