2

uuencode是否可以使用and发送多个附件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变量中?

4

2 回答 2

6

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
于 2014-01-20T13:12:10.737 回答
1

对于它的价值,mailx也很好用。

mailx -s "Subject" -a attachment1 -a attachement2 -a attachment3 email.address@domain.com < /dev/null
于 2020-12-01T17:29:05.073 回答