Skip to content
Advertisement

Incorrect format of sending mail from Linux shell

My file format is as below:

cat myfile.txt

Size of user01 is  1863 MB, it over than 100 MB
Size of user02 is  1863 MB, it over than 100 MB
Size of user03 is  815 MB, it over than 100 MB

But if I mail it to my mailbox,

cat ./myfile.txt | mail -s "This is test Mail" myemail@domain.com

the format will be as below:

Size of user01 is 1863 MB, it over than 100 MB Size of user02 is 1863 MB, it over than 100 MB Size of user03 is 815 MB, it over than 100 MB

How can I keep my original format when I send file content to my mailbox!?

Advertisement

Answer

The SMTP specification says that end-of-line in SMTP messages is

 rn   (return+newline)

where in Unix/Linux the end of line is

 n  (newline)

Run the text though a tr filter to convert all the n to rn — or pipe it through unix2dos which does the same thing, like;

cat ./myfile.txt | unix2dos | mail -s "This is test Mail" myemail@domain.com
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement