2014-01-20 126 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 
相关问题