提问人:Binara Medawatta 提问时间:11/16/2023 更新时间:11/16/2023 访问量:16
如何使用 NodeJS 将多个文件作为附件附加到 AWS SES 中,其中包含 MIME 文本?
How do you attach multiple files as attachments in AWS SES with MIME texts using NodeJS?
问:
我正在使用 AWS SES 发送带有附件的电子邮件,由于 sendEmail 函数目前无法发送附件,因此我在 SES 中使用 sendRawEmail 函数。为了发送原始电子邮件,我已将电子邮件转换为MIME文本,如下所示。它有两个附件(转换为 base64 的图像)、一个正文和一些标题。
From: [email protected]
To: [email protected]
Cc:
Bcc:
Subject: Test from Lambda
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_Part2904462804807624"
------=_Part2904462804807624
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hello world
------=_Part2904462804807624
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<h1>Hello</h1><p>world</p>
------=_Part2904462804807624
Content-Type: image/jpeg; name="sea-surface-turquoise-blue-color-background-some-reflections-calm-crystal-clear-water-small-ripples-sea-surface-turquoise-221064440.jpg"
Content-Description: sea-surface-turquoise-blue-color-background-some-reflections-calm-crystal-clear-water-small-ripples-sea-surface-turquoise-221064440.jpg
Content-Disposition: attachment;filename="sea-surface-turquoise-blue-color-background-some-reflections-calm-crystal-clear-water-small-ripples-sea-surface-turquoise-221064440.jpg";
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQAAAQABAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/
.....................................
.....................................
.....................................
MOO3FwVjiwfsg1fcci0NRnULhYioZ2KOJRlg33mWBSNrslR+COggrOdzIshEqj4ghEN3WU6jhDlg8zDHGYoRsMNKcauLzWjjzBY26eC5ZFlpeI0fITV8EdMstRZcj4mTDEpYYeTuUa1+yBUdHBcs8rdahAOUiCgJLUZEn/9k=
------=_Part2904462804807624--
Content-Type: image/jpeg; name="image.desktop.size-xl.sme-greenoption-xl1280x720.jpeg"
Content-Description: image.desktop.size-xl.sme-greenoption-xl1280x720.jpeg
Content-Disposition: attachment;filename="image.desktop.size-xl.sme-greenoption-xl1280x720.jpeg";
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCALQBQADASIAAhEBAxEB/
.....................................
.....................................
.....................................
ojzPGee6OP61rQa14b06zmutOtLmw1KJSsSTpvILcZV+gx7it/wJaNeeEbqGWK2uIgSttHKoIRwD8p7gZx/Sli023sNae2j0mzS9njKkGcm3kTA3ADdlST6qc150q1HmdNrbs/0Dof/2Q==
------=_Part2904462804807624--
------=_Part2904462804807624--
我已经删除了 base64 编码的一部分,因为它太长了。此 MIME 文本适用于 SES,但仅附加第一个文件。第二个文件未附加到电子邮件中。我已经单独测试了第二个文件,它工作正常。MIME 文本可能有什么问题?
答:
0赞
Binara Medawatta
11/16/2023
#1
找到了此问题的原因。在 MIME 文本中,最终边界应以双破折号结尾--.但就我而言,我使用了双破折号来分隔两个附件,这导致在没有最终附件的情况下结束 MIME 文本多部分边界。以下是用于添加多个附件的更正 MIME 文本。
From: [email protected]
To: [email protected]
Cc:
Bcc:
Subject: Test from Lambda
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_Part2904462804807624"
------=_Part2904462804807624
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hello world
------=_Part2904462804807624
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<h1>Hello</h1><p>world</p>
------=_Part2904462804807624
Content-Type: image/jpeg; name="sea-surface-turquoise-blue-color-background-some-reflections-calm-crystal-clear-water-small-ripples-sea-surface-turquoise-221064440.jpg"
Content-Description: sea-surface-turquoise-blue-color-background-some-reflections-calm-crystal-clear-water-small-ripples-sea-surface-turquoise-221064440.jpg
Content-Disposition: attachment;filename="sea-surface-turquoise-blue-color-background-some-reflections-calm-crystal-clear-water-small-ripples-sea-surface-turquoise-221064440.jpg";
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQAAAQABAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/
.....................................
.....................................
.....................................
MOO3FwVjiwfsg1fcci0NRnULhYioZ2KOJRlg33mWBSNrslR+COggrOdzIshEqj4ghEN3WU6jhDlg8zDHGYoRsMNKcauLzWjjzBY26eC5ZFlpeI0fITV8EdMstRZcj4mTDEpYYeTuUa1+yBUdHBcs8rdahAOUiCgJLUZEn/9k=
------=_Part2904462804807624
Content-Type: image/jpeg; name="image.desktop.size-xl.sme-greenoption-xl1280x720.jpeg"
Content-Description: image.desktop.size-xl.sme-greenoption-xl1280x720.jpeg
Content-Disposition: attachment;filename="image.desktop.size-xl.sme-greenoption-xl1280x720.jpeg";
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCALQBQADASIAAhEBAxEB/
.....................................
.....................................
.....................................
ojzPGee6OP61rQa14b06zmutOtLmw1KJSsSTpvILcZV+gx7it/wJaNeeEbqGWK2uIgSttHKoIRwD8p7gZx/Sli023sNae2j0mzS9njKkGcm3kTA3ADdlST6qc150q1HmdNrbs/0Dof/2Q==
------=_Part2904462804807624
------=_Part2904462804807624--
评论