0

我正在尝试通过 AWS 简单电子邮件服务发送附件,我可以让它发送没有附件的原始电子邮件,但是当我尝试使用附件时它总是失败。我是否正确构建了我的 MIME 消息?

好的,这是正确发送的 MIME:

From: test@example.com
To: test@example.com
Subject: Test Email
Content-Type: multipart/mixed;
  boundary="_003_97DCB304C5294779BEBCFC8357FCC4D2"
MIME-Version: 1.0

--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello, This is a test email.

当我附加附件时无法发送:

From: test@example.com
To: test@example.com
Subject: Test Email
Content-Type: multipart/mixed;
  boundary="_003_97DCB304C5294779BEBCFC8357FCC4D2"
MIME-Version: 1.0

--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello, This is a test email.

--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/txt; name="test.txt"
Content-Description: test.txt
Content-Disposition: attachment; filename="test.txt";
Content-Transfer-Encoding: base64

VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudC4=

--_003_97DCB304C5294779BEBCFC8357FCC4D2

有什么明显的错误吗?

我通过对整个消息进行 base64 编码并将其添加到此 URL 的末尾来构建调用:

Action=SendRawEmail&Destinations.member.1=test%40example.com&RawMessage.Data={base64 encoded MIME Message}

回答:

MIME 文件有两个问题。第一的

  • 尾随边界不应该在那里,因为它显然是在寻找 MIME 消息的另一个方面,例如另一个附件。

  • 定义为“text/txt”的 Content-Type 实际上应该是“text/plain”

因此,通过这两个更改,您会得到这个有效的 MIME 消息:

From: test@example.com
To: test@example.com
Subject: Test Email
Content-Type: multipart/mixed;
  boundary="_003_97DCB304C5294779BEBCFC8357FCC4D2"
MIME-Version: 1.0

--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello, This is a test email.

--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain; name="test.txt"
Content-Description: test.txt
Content-Disposition: attachment; filename="test.txt";
Content-Transfer-Encoding: base64

VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudC4=
4

1 回答 1

0

MIME 文件有两个问题。第一的

  • 尾随边界不应该在那里,因为它显然是在寻找 MIME 消息的另一个方面,例如另一个附件。

  • 定义为“text/txt”的 Content-Type 实际上应该是“text/plain”

因此,通过这两个更改,您会得到这个有效的 MIME 消息:

From: test@example.com
To: test@example.com
Subject: Test Email
Content-Type: multipart/mixed;
  boundary="_003_97DCB304C5294779BEBCFC8357FCC4D2"
MIME-Version: 1.0

--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello, This is a test email.

--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain; name="test.txt"
Content-Description: test.txt
Content-Disposition: attachment; filename="test.txt";
Content-Transfer-Encoding: base64

VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudC4=
于 2012-03-30T10:28:21.797 回答