使用AWS SES CLI发送电子邮件附件

问题描述 投票:0回答:3

我正在尝试使用SES CLI发送电子邮件附件,但每次邮件到达并打开附件时我都会在Adobe中收到错误消息:

无法打开文件,因为它不是受支持的文件类型,或者因为文件已损坏。

我正在使用的命令是:

aws ses send-raw-email --raw-message file:///root/AWS/INSPECTOR/message.json

该文件的内容是:

{
   "Data": "From: [email protected]\nTo: [email protected]\nSubject: Test email sent using the AWS CLI (contains an attachment)\nMIME-Version: 1.0\nContent-type: Multipart/Mixed; boundary=\"NextPart\"\n\n--NextPart\nContent-Type: text/plain\n\nThis is the message body.\n\n--NextPart\nContent-Type: application/pdf;\nContent-Disposition: attachment; filename=\"report.pdf\";\npath=\"\/tmp\/report.pdf\"\n\n--NextPart--"
}

我在http://docs.aws.amazon.com/cli/latest/reference/ses/send-raw-email.html看到了这个页面,但是我的语法不太正确,所以任何帮助都会受到赞赏....

amazon-web-services aws-cli amazon-ses
3个回答
1
投票

附件应以Base64编码传递,并在MIME中指定Content-Transfer-Encoding:base64。

这是我回答的前一个帖子的链接:Sending aws cli SES as a file attachmennt


0
投票

您尝试调整的示例会添加纯文本并将其嵌入到电子邮件中。您正在尝试添加pdf,但是您只是将标题添加到邮件中,但您没有添加pdfs内容。

您还需要嵌入pdf base64编码。

快速搜索这个answer到略有不同的问题“How to embed images in email”可能会帮助您嵌入。在这种情况下,您想要嵌入pdf而不是图像。

如果正确准备你的json,它应该与aws-cli一起使用。


0
投票

我能够为大学写一些代码来解决普通/文本的相同问题。我确实用PDF类型尝试了这个,但不幸的是我无法正常工作,收到的文件似乎已损坏。我认为对于其他文件类型,您必须在base64中对其进行编码,但不确定与cli一起使用的确切结构。

echo'{“Data”:“From:[email protected] \ nTo:[email protected] \ nSubject:[Subject] \ nMIME-Version:1.0 \ nContent-type:Multipart / Mixed; boundary = \”NextPart \ “\ n \ n - NextPart \ nContent-Type:text / plain \ n \ n [Body] \ n \ n - NextPart \ nContent-Type:text / plain; \ nContent-Disposition:attachment; filename = \” test.txt \“\ n \ n'$(cat ./input.txt)'\n--NextPart--”}'> message.json&aws ses send-raw-email --region eu-west-1 --raw-message file://./message.json

实际上,中间的cat命令将文本写入message.json,以便它可以是动态的。希望这有助于某人。

编辑

感谢@James Dean:

以下是PDF附件的示例:

echo'{“Data”:“From:[email protected] \ nTo:[email protected] \ nSubject:[Subject] \ nMIME-Version:1.0 \ nContent-type:Multipart / Mixed; boundary = \”NextPart \ “\ n \ n - NextPart \ nContent-Type:text / plain \ n \ n [Body] \ n \ n - NextPart \ nContent-Type:application / pdf; \ nConContent-Disposition:attachment; \ nContent-Transfer -Encoding:base64; filename = \“test.pdf \”\ n \ n'$(base64 test.pdf)'\ n - NextPart--“}'> message.json&aws ses send-raw-email - -region eu-west-1 --raw-message file://./message.json

干杯,

阿列克谢蓝。

© www.soinside.com 2019 - 2024. All rights reserved.