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.
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.)
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>