【问题标题】:Send email attachment using AWS SES CLI使用 AWS SES CLI 发送电子邮件附件
【发布时间】:2019-04-17 18:36:09
【问题描述】:

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

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

我使用的命令是:

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

那个文件的内容是:

{
   "Data": "From: sender@exmple.com\nTo: recipient@example.com\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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      echo '{"Data": "From: from@domain.com\nTo: to@domain.com\nSubject: [主题]\nMIME 版本:1.0\n内容类型:Multipart/Mixed; 边界=\"NextPart\"\n\n--NextPart\nContent-Type: text/plain\n\n[正文]\n\n--NextPart\nContent-Type: text/plain;\nContent-Disposition: 附件; 文件名=\"test.txt\"\n\n'$(cat ./input.txt)'\n--NextPart--"}' > message.json & aws ses send-raw-email --region eu-west-1 --raw-message 文件://./message.json

      本质上是中间的 cat 命令将文本写入 message.json 以便它可以是动态的。希望这对某人有所帮助。

      编辑

      感谢@James Dean:

      以下是带有 PDF 附件的示例:

      echo '{"Data": "From: from@domain.com\nTo: to@domain.com\nSubject: [主题]\nMIME 版本:1.0\n内容类型:Multipart/Mixed; 边界=\"NextPart\"\n\n--NextPart\nContent-Type: text/plain\n\n[正文]\n\n--NextPart\nContent-Type: 应用程序/pdf;\n内容处置: 附件;\n内容传输编码:base64; 文件名=\"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

      干杯,

      阿列克谢蓝。

      【讨论】:

        【解决方案3】:

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

        您还需要嵌入 pdf base64 编码。

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

        如果正确准备您的 json 并且它应该可以与 aws-cli 一起使用。

        【讨论】:

          猜你喜欢
          • 2022-11-25
          • 1970-01-01
          • 2015-03-29
          • 2011-08-07
          • 2020-10-20
          • 2017-11-11
          • 1970-01-01
          • 2017-09-28
          • 2019-12-07
          相关资源
          最近更新 更多