Reputation: 4577
On this question I asked about what the structure of the email should be. This question is about how to use cfmail (and cfmailpart, cfmailparam, etc.) to produce the correct structure.
The desired structure is:
multipart/mixed
multipart/alternative
text/plain
text/html
image/jpeg
application/pdf
The code I've got currently:
<cfmail from='"No Reply" <[email protected]>' subject="Test 123" to="[email protected],[email protected]">
<!--- 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>
However, this produces this structure:
multipart/mixed
multipart/alternative
text/plain
multipart/related
text/html
image/jpeg
application/pdf
I've tried code like this:
<cfmail from='"No Reply" <[email protected]>' subject="Test 123" to="[email protected],[email protected]">
<!--- 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>
But then it just goes to the undelivered email list in cfadmin.
With both versions of the code I tried for values of the type
attribute on the cfmail
tag itself:
to no avail.
How do I achieve the desired MIME structure in ColdFusion?
Upvotes: 2
Views: 214
Reputation: 4577
My approach I landed on may not be ideal, but it works in all 3 mail clients I was targeting. What I ended up doing was this:
contentID
attribute on the cfmailparam
tag and include an <img src="cid:...">
with the contentID
valuecontentID
attribute on the cfmailparam
tagThis has the end result that all images are presented inline in the message body, and all other files are displayed as regular file attachments.
Based on the discussion by who I assume is a developer on the CF team here https://tracker.adobe.com/#/view/CF-4166939 I'm under the impression that the MIME header structure is controlled by ColdFusion and isn't directly manageable by ColdFusion developers. Unfortunate, but at least I have something of a workaround. Hopefully this will help someone.
Upvotes: 1