coldfusion - 控制使用 cfmail 生成的电子邮件的 MIME 结构
问题描述
在这个问题上,我询问了电子邮件的结构应该是什么。这个问题是关于如何使用 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 中未发送的电子邮件列表。
对于两个版本的代码,我都尝试了标签本身的type
属性值:cfmail
- 清楚的
- html
- 多部分/混合
- 多部分/替代
无济于事。
如何在 ColdFusion 中实现所需的 MIME 结构?
解决方案
我采用的方法可能并不理想,但它适用于我所针对的所有 3 个邮件客户端。我最终做的是:
- 对于任何图像附件,我会在标签上包含一个
contentID
属性并包含一个带有值的cfmailparam
<img src="cid:...">
contentID
- 对于所有其他附件,我省略了标签
contentID
上的属性cfmailparam
最终结果是所有图像都内嵌在消息正文中,所有其他文件都显示为常规文件附件。
根据我假设是 CF 团队开发人员的讨论https://tracker.adobe.com/#/view/CF-4166939我的印象是 MIME 标头结构由 ColdFusion 控制并且不是不能由 ColdFusion 开发人员直接管理。不幸的是,但至少我有一些解决方法。希望这会对某人有所帮助。
推荐阅读
- javascript - 虽然设置了 keyExtractor,但我得到了 VirtualizedList:缺少项目的键,请确保指定一个键或提供自定义 keyExtractor
- spring-tool-suite - 为什么 spring-tool-suite-4-4.10.0.RELEASE-e4.19.0-win32.win32.x86_64.self-extracting.jar 对我的电脑有害
- knative - 使用“kn service update hello-example --request”设置资源限制时出错
- javascript - 为多个系列创建多个 Pie Highcharts
- java - 我无法在 win10 上使用 `mvn spring-boot:build-image` 和远程 docker 守护进程
- dolphindb - 使用 group by 时 DolphinDB 中的错误消息
- c# - 使用 QuickSort 对字符串中的字符进行排序
- arrays - 使用 kotlin 如何将数组附加到二维数组
- python-3.x - 为什么 print 函数在方法中不起作用:get_details() 并且没有为 print(x.increment_odometer) 返回?
- c# - 如何正确键入声明为类属性的 LINQ 请求?