2016-05-13 94 views
1

我的文件格式如下:格式不正確外殼

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" [email protected] 

格式將是如下:

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 

當我將文件內容發送到我的郵箱時,如何保留原始格式!?

+0

我剛剛在我的系統上試過,郵件格式正確。這聽起來像是你的'sendmail'或'postfix'軟件的配置有問題。 – Barmar

回答

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" [email protected] 
+0

感謝您的快速響應。 安裝unix2dos並嘗試執行命令後,我收到附件中的郵件。 可以保留文本格式嗎? – Ilikeperl

+0

MTA應將郵件內容從Unix格式轉換爲SMTP格式。在管道到郵件之前沒有必要這樣做。 – Barmar

+0

@Soren我想再次感謝您的介紹。 我試過一些測試: 'cat myfile.txt | unix2dos | mail -s「這是測試郵件」myname @ mydomain.com「 但是我沒有收到郵件中的文件內容,而是收到了一個名爲AT00001.bin的附件。 我試過Mutt 'cat size_report.txt | unix2dos | mutt -s「這是測試郵件」yiweis @ sparqtron.com' 這就是我想要的。我收到文件 的內容非常感謝! – Ilikeperl

0

您可以嘗試使用與內容類型的HTML郵件的命令,並使用HTML 標籤得到它。

echo "<pre>`cat myfile.txt`</pre>" | mail -a "Content-type: text/html" -s "This is test Mail" [email protected] 
+0

非常感謝您的協助。 我試過了你提供的代碼。但系統顯示錯誤信息: 「Content-type:text/html:沒有這樣的文件或目錄」。如果我輸入 'echo「

'cat myfile.txt'
」| mail -s「這是測試郵件」myname @ mydomain.com「。我收到了具有相同格式的郵件,只需添加
即可。我的代碼中是否有拼寫錯誤? –
                        
                            
    Ilikeperl