是否可以使用uuencode
和sendmail
发送多个附件?
在脚本中,我有一个变量,其中包含需要附加到单个电子邮件的文件,如:
$attachments=attachment_1.pdf attachment_2.pdf attachment_3.pdf attachment_4.pdf
还有一个$template
变量,如:
$template="Subject: This is the subject
From: no-reply@domain.com
To: %s
Content-Type: text/plain
This is the body.
"
我想出了:
printf "$template" "$recipient" |
sendmail -oi -t
在此我必须在$attachments
变量中附加所有内容?
答案 0 :(得分:4)
attachments="attachment_1.pdf attachment_2.pdf attachment_3.pdf attachment_4.pdf"
recipient='john.doe@example.net'
# () 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: no-reply@domain.com
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
答案 1 :(得分:0)
就其价值而言,mailx
也很好用。
mailx -s "Subject" -a attachment1 -a attachement2 -a attachment3 email.address@domain.com < /dev/null