从Linux shell发送邮件的格式不正确

时间:2016-05-13 00:54:46

标签: linux shell

我的文件格式如下:

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

但如果我把它邮寄到我的邮箱,

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

格式如下:

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

将文件内容发送到邮箱时,如何保留原始格式??

2 个答案:

答案 0 :(得分:1)

SMTP specification表示SMTP邮件中的行尾是

 \r\n   (return+newline)

在Unix / Linux中,行尾是

 \n  (newline)

通过tr过滤器运行文本,将所有\ n转换为\ r \ n - 或通过unix2dos管道,它执行相同的操作,例如;

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

答案 1 :(得分:0)

您可以尝试使用内容类型为html的mail命令,并使用html pre 标记来获取它。

echo "<pre>`cat myfile.txt`</pre>" | mail -a "Content-type: text/html" -s "This is test Mail" myemail@domain.com