2014-01-20 158 views
1

是否可以使用uuencodesendmail發送多個附件?使用命令行和sendmail發送包含多個附件的電子郵件

在腳本我有一個包含需要被附加到一個單一的類似電子郵件的文件變量:

$attachments=attachment_1.pdf attachment_2.pdf attachment_3.pdf attachment_4.pdf 

另外一個$template變量,如:

$template="Subject: This is the subject 
From: [email protected] 
To: %s 
Content-Type: text/plain 

This is the body. 
" 

我來了與:

printf "$template" "$recipient" | 
sendmail -oi -t 

在這個地方的某處我必須附加一切在​​變量?

+0

是[mailx](http://en.wikipedia.org/wiki/Mailx)的一個選項嗎?如果是這樣,您可以簡單地使用'-a'開關發送多封電子郵件。你有*使用vanilla sendmail嗎? –

+0

檢查在http://stackoverflow.com/questions/19940292/using-uuencode-to-attach-multiple-attachments-from-a-variable-to-an-e-mail-and-s上的答案它會給你一個想法如何通過uuencode解析包含附件的變量。 – Incognito

回答

4
attachments="attachment_1.pdf attachment_2.pdf attachment_3.pdf attachment_4.pdf" 
recipient='[email protected]' 

#() sub sub-shell should generate email headers and body for sendmail to send 
(
# generate email headers and begin of the body asspecified by HERE document 
cat - <<END 
Subject: This is the subject 
From: [email protected] 
To: $recipient 
Content-Type: text/plain 

This is the body. 

END 
# generate/append uuencoded attachments 
for attachment in $attachments ; do 
    uuencode $attachment $attachment 
done 
) | /usr/sbin/sendmail -i -- $recipient 
相關問題