2011-11-29 75 views
9

我寫一個shell script發送使用Linux Mailx電子郵件簡單郵件正文+附件文件,電子郵件必須包含文件附件消息體發送使用Linux的mailx

目前發送郵件帶有附件:

output.txt | mail -s "Daily Monitoring" [email protected] 

我想補充一個消息體。我該如何?

的Linux的mailx:

mail [-eIinv] [-a header] [-b addr] [-c addr] [-s subj] to-addr 
+1

這應該有所有問題的答案:http://stackoverflow.com/questions/17359/how-do-i-send-a-文件-AS-使用-Linux的命令行的電子郵件附連-/ 14213935#14213935 –

回答

20

的常用方法是使用uuencode的附件和echo對身體:

(uuencode output.txt output.txt; echo "Body of text") | mailx -s 'Subject' [email protected] 

對於Solaris和AIX,您可能需要首先把echo聲明:

(echo "Body of text"; uuencode output.txt output.txt) | mailx -s 'Subject' [email protected] 
0

Johnsyweb的回答並沒有爲我工作,但它爲我工作與馬特:

echo "Message body" | mutt -s "Message subject" -a myfile.txt [email protected] 
2

最好的辦法是使用MPack,還將!

MPack,還將-s 「主題」 -D 「./body.txt」 「././image.png」 有電子郵件地址

MPack,還將 - 主題 - 身體 - 附件 - 有電子郵件地址

0

你可以試試這個:

(cat ./body.txt)|mailx -s "subject text" -a "attchement file" [email protected] 
1

試試這個工作對我來說:

(echo "Hello XYX" ; uuencode /export/home/TOTAL_SI_COUNT_10042016.csv TOTAL_SI_COUNT_10042016.csv) | mailx -s 'Script test' [email protected] 
0

在RHEL Linux的,我有麻煩我的郵件中電子郵件正文,而不是作爲附件。使用od -cx,我發現我的電子郵件正文包含幾個/ r。我使用perl腳本去除/ r,並且郵件正確地插入到電子郵件的正文中。

mailx -s "subject text" [email protected] < 'body.txt' 

文本文件body.txt包含char \ r,所以我用perl去掉\ r。

cat body.txt | perl success.pl > body2.txt 
mailx -s "subject text" [email protected] < 'body2.txt' 

這是success.pl

while (<STDIN>) { 
     my $currLine = $_; 
     s?\r??g; 
     print 
    } 
; 
相關問題