将 PDF 文件附加到使用 AWS SES 发送的电子邮件

Attaching PDF file to email sent with AWS SES

我想使用 AWS SDK 从 nodejs 服务器发送电子邮件并附加 pdf 文件。 考虑过将文件上传到 S3 并通过电子邮件发送 link,但后来我无法创建存储桶 public,因此此选项无效。现在我拥有 EC2 实例上的所有数据,如何将可下载的 PDF 附加到我想使用 SES 发送的原始(模板化,但不一定是)电子邮件?

在 AWS 文档中搜索了所有内容,但一无所获。我认为这并不罕见,所以任何见解都会有所帮助。

P.S。我不想使用第三方模块,因为我不想向未知模块提供我的凭据。

由于您的要求是没有第三方库,因此您必须自己编写。这不是太难,但也不容易。

我的建议可能会满足您的要求,那就是选择一个只创建电子邮件消息和 returns 字符串的库。然后您的私有代码可以管理凭据和对 SES 的调用。我不知道有这样的库,但您可以选择一个开源 node.js 包并提取您需要的代码。然后只重新发布该部分,以便其他人可以像您对原作者的贡献一样受益。

对于 Amazon SES,您将需要使用 SendRawEmail 操作。然后你将不得不手工制作消息的正文。

以下是如何设置电子邮件格式的示例:

From: "Sender Name" <sender@example.com>
To: recipient@example.com
Subject: Customer service contact info
Content-Type: multipart/mixed;
    boundary="a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a"

--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: multipart/alternative;
    boundary="sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a"

--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Please see the attached file for a list of customers to contact.

--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

<html>
<head></head>
<body>
<h1>Hello!</h1>
<p>Please see the attached file for a list of customers to contact.</p>
</body>
</html>

--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a--

--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: text/plain; name="customers.txt"
Content-Description: customers.txt
Content-Disposition: attachment;filename="customers.txt";
    creation-date="Sat, 05 Aug 2017 19:35:36 GMT";
Content-Transfer-Encoding: base64

SUQsRmlyc3ROYW1lLExhc3ROYW1lLENvdW50cnkKMzQ4LEpvaG4sU3RpbGVzLENhbmFkYQo5MjM4
OSxKaWUsTGl1LENoaW5hCjczNCxTaGlybGV5LFJvZHJpZ3VleixVbml0ZWQgU3RhdGVzCjI4OTMs
QW5heWEsSXllbmdhcixJbmRpYQ==

--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a--

这个link会进一步解释:

Sending Raw Email