gpt4 book ai didi

bash - 使用命令行和 sendmail 发送带有多个附件的电子邮件

转载 作者:行者123 更新时间:2023-12-01 22:37:11 28 4
gpt4 key购买 nike

uuencodesendmail 可以发送多个附件吗?

在脚本中我有一个变量,其中包含需要附加到单个电子邮件的文件,例如:

$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 附件并通过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

关于bash - 使用命令行和 sendmail 发送带有多个附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21231174/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com