gpt4 book ai didi

amazon-web-services - 如何在 NodeJS 中使用 AWS SES 发送附件?

转载 作者:行者123 更新时间:2023-12-04 13:44:07 29 4
gpt4 key购买 nike

根据“https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendTemplatedEmail-property”中的给定文档。它使用“ sendTemplatedEmail ” API,我们可以使用模板发送电子邮件。它成功了。但是我不知道如何向它添加附件。

在“ sendTemplatedEmail ” API 文档的第 4 点中,它说“邮件的总大小,包括附件,必须小于 10 MB”。如何在此 sendTemplatedEmail API 中添加附件?

还有一个名为“ sendRawEmail ”的API。但这不符合我的要求。我需要使用模板并附加文档。有谁知道该怎么做??

最佳答案

看一下 SendRawEmail 示例:

/* The following example sends an email with an attachment: */

var params = {
Destinations: [],
FromArn: "",
RawMessage: {
Data: <Binary String>
},
ReturnPathArn: "",
Source: "",
SourceArn: ""
};
ses.sendRawEmail(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
/*
data = {
MessageId: "EXAMPLEf3f73d99b-c63fb06f-d263-41f8-a0fb-d0dc67d56c07-000000"
}
*/
});

引用: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html

重要提示:您需要了解 MIME 类型标准才能包含您的附件。看看 this article .

MIME was defined in 1992 by the Internet Engineering Task Force (IETF). The distinguishing characteristic of a MIME message is the presence of the MIME headers. As long as your mail recipients also have e-mail software that is MIME-compliant (and most e-mail software is), you can swap files containing attachments automatically.



编辑: This article解释如何在你的 body 中包含依恋。

MIME completes the illusion of file attachments by allowing the message body to be divided into distinct parts, each with their own headers. The content type multipart/mixed means that the content of the body is divided into blocks separated by "--" + a unique string guaranteed to not be found anywhere else in the message. If you say that your boundary string is "MyBoundaryString", then all occurrences of that string will be treated as a boundary. So it better not be in the message the user typed or it won't be decoded correctly.



Wikipedia还举了个例子:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=frontier

This is a message with multiple parts in MIME format.
--frontier
Content-Type: text/plain

This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
--frontier--

我假设您熟悉 Base64 .

关于amazon-web-services - 如何在 NodeJS 中使用 AWS SES 发送附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52151723/

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