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

标签 bash email sendmail uuencode

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/

相关文章:

java - 通过 Java 使用 gmail 发送电子邮件

php - 使用变量 PHP 向正确的用户发送电子邮件

email - Gitlab、docker 和 sendmail 端口

java - 使用 javax 在 RCP Java 应用程序中发送带有附件的电子邮件

linux - 从文件 linux/bash 读取输入

bash - 在两个命令之间的管道中添加一个大缓冲区

linux - 如何永久存储文本模式浏览器的代理信息(例如链接)

PHP 页面不发送电子邮件

PHP mail() 从命令行工作但不是 apache

bash - 使用bash输入c程序的stdin