我使用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文本可能有什么问题?
的数据
1条答案
按热度按时间4xy9mtcn1#
找到了这个问题的原因。在MIME文本中,最后的边界应该以双破折号结束--。但在我的情况下,我使用双破折号来分隔两个附件,这导致MIME文本多部分边界结束时没有最后的附件。以下是更正的MIME文本添加多个附件。
字符串