控制使用 cfmail 生成的电子邮件的 MIME 结构

Control MIME structure of emails produced with cfmail

this question 我询问了电子邮件 应该 的结构。这个问题是关于如何使用 cfmail(以及 cfmailpart、cfmailparam 等)来生成正确的结构。

所需的结构是:

multipart/mixed
  multipart/alternative
    text/plain
    text/html
  image/jpeg
  application/pdf

我目前得到的代码:

 <cfmail from='"No Reply" <noreply@example.com>' subject="Test 123" to="my_outlook_address@example.com,my_gmail_address@gmail.com">

  <!--- Some code to get a query of attachment content here... --->

  <cfloop query="qAttachments">
      <!---
          Some code to get the attachment file data here and put it in a variable named `myfile`... 

          myfile structure:
          {
              fileName: <string>,
              fileContent: <base64 encoded file content>,
              mimeType: <image/jpeg for the one, application/pdf for the other>
          }
      --->
      <cfmailparam disposition="attachment" contentID="#myfile.fileName#" content="#myfile.fileContent#" file="#myfile.fileName#" type="#myfile.mimeType#" />

  </cfloop>

  <cfmailpart type="plain">
      My plain text
  </cfmailpart>

  <cfmailpart type="html">
      <strong>My fancypants text</strong>
  </cfmailpart>
</cfmail>

然而,这会产生这个结构:

multipart/mixed
  multipart/alternative
    text/plain
    multipart/related
      text/html
      image/jpeg
      application/pdf

我试过这样的代码:

<cfmail from='"No Reply" <noreply@example.com>' subject="Test 123" to="my_outlook_address@example.com,my_gmail_address@gmail.com">

  <!--- Some code to get a query of attachment content here... --->

  <cfloop query="qAttachments">       
      <cfmailparam disposition="attachment" contentID="#myfile.fileName#" content="#myfile.fileContent#" file="#myfile.fileName#" type="#myfile.mimeType#" />

  </cfloop>

  <cfmailpart type="multipart/alternative">
    <cfmailpart type="plain">
      My plain text
    </cfmailpart>

    <cfmailpart type="html">
      <strong>My fancypants text</strong>
    </cfmailpart>
  </cfmailpart>
</cfmail>

但它只是转到 cfadmin 中的未送达电子邮件列表。

对于两个版本的代码,我都尝试了 cfmail 标签本身的 type 属性值:

无济于事。

如何在 ColdFusion 中实现所需的 MIME 结构?

我采用的方法可能并不理想,但它适用于我定位的所有 3 个邮件客户端。我最终做的是这样的:

  • 对于任何图像附件,我会在 cfmailparam 标签上包含一个 contentID 属性,并包含一个 <img src="cid:...">contentID
  • 对于所有其他附件,我省略了 cfmailparam 标签上的 contentID 属性

最终结果是所有图像都以内嵌方式显示在消息中 body,所有其他文件都显示为常规文件附件。

根据我认为是 CF 团队开发人员的讨论https://tracker.adobe.com/#/view/CF-4166939 我的印象是 MIME header 结构由 ColdFusion 控制,而不是直接控制可由 ColdFusion 开发人员管理。不幸的是,但至少我有一些解决方法。希望这会对某人有所帮助。