loading...

Do not use CFMailPart "WrapText" with HTML

gamesover profile image James Moberg ・2 min read

We encountered a strange issue this week where client-provided HTML wasn't being displayed consistently in all email clients. Some of the received message text was being displayed incorrectly, but it appeared correct when previewed prior to being sent.

After reviewing their HTML and experimenting with a global email handler that we've used for years, we determined it was due to using a WRAPTEXT parameter on the CFMailPart tag. One example was an inline CSS rule that used the font "Times Roman". The wraptext option would occasionally insert a line break in the midst of the font name due to the context-insensitive wordwrap logic.

I'm not sure if this is a bug, but it seems like one. (I've reported it. Bug CF-4208015) We've used this parameter for years under the assumption that it would correctly wrap long HTML to ensure that it's compliant. We incorrectly assumed that adding wraptext="900" would help ensure that long HTML lines would be safely wrapped. I'm pretty sure that this was tested a one point in the past, but we've been using Coldfusion since v3 and we keep discovering built-in functions behaving a little differently (ie, incorrectly) in newer versions.

The Internet Message Format RFC 5322
2.1.1. Line Length Limits
There are two limits that this standard places on the number of characters in a line. Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF.

Comparison of Generated HTML Screenshot

Here's what the resultant HTML looks like when delivered to a Gmail address. (NOTE: The right-side is supposed to indicate "900 characters". I used the VSCode Render Line Endings extension so that the end-of-line characters would be visible.)

CFMailPart using WrapText parameter

Solution / Work-Around

The MailPart tag should probably be updated to ignore the wraptext parameter if the type is "HTML". Since it's not ignoring the value and using it negatively impacts the resultant HTML, we highly recommend checking your CFML code to ensure that this option is not used for HTML content within the CFMAILPART tag.

<!--- HTML wrapped correctly; short 76 character lines delimited with "=" --->
<cfmailpart type="html" charset="utf-8">#myHTML#</cfmailpart>

<!--- HTML wrapped incorrectly; long ~900 character lines --->
<cfmailpart type="html" wraptext="900" charset="utf-8">#myHTML#</cfmailpart>

Posted on Mar 2 by:

gamesover profile

James Moberg

@gamesover

I’m a ColdFusion web application developer at SunStar Media located in Monterey, CA. I am a fan of technology, music and web development.

Discussion

markdown guide
 

I've been running into this issue with CFMailPart on Lucee 5.2 every since we converted. There's a bug in Lucee in which it ignores the wraptext value. It's been updated in later releases of Lucee; but, I haven't been able to upgrade yet. It's showing up in the exact same way for us - the inline style attributes are breaking in strange places. I've been trying to find ways to make sure the breaks happen in more predictable ways; but, it hasn't been a high-priority at work :(

Really, I Just need to upgrade Lucee!!