Bash 使用命令行和sendmail发送包含多个附件的电子邮件
是否可以使用Bash 使用命令行和sendmail发送包含多个附件的电子邮件,bash,email,sendmail,uuencode,Bash,Email,Sendmail,Uuencode,是否可以使用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
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
变量?uuencode
attachments中的所有内容,并通过sendmail
发送MIME附件更好。uuencode
更容易在脚本中实现,但一些客户端不支持它
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
attachments=“附件1.pdf附件2.pdf附件3.pdf附件4.pdf”
约翰。doe@example.net'
#()子shell应生成sendmail要发送的电子邮件头和正文
(
#生成此处文档指定的电子邮件标题和正文开头
cat-不管它值多少钱,mailx
也很有效
mailx -s "Subject" -a attachment1 -a attachement2 -a attachment3 email.address@domain.com < /dev/null
mailx-s“主题”-附件1-附件2-附件3电子邮件。address@domain.com
是一个选项吗?如果是这样,您可以简单地使用-a
开关发送多封电子邮件。您必须使用vanilla sendmail吗?检查它的答案会让您了解如何通过uuencode解析包含附件的变量。uuencode对我有效,但它将一些noname文件作为附件发送。如何避免这种情况?