Small formatting issue with emails sent via ColdFusion 9 Mail.cfc

This post is more than 2 years old.

Using the new mail.cfc to send emails in ColdFusion 9? You may notice an odd formatting issue. Check out this screen shot:

I thought this was whitespace in my code, but turns out it is the code that implements mail in script. Find base.cfc in your cf install\customtags\com\adobe\coldfusion folder. Open it and go to line 417. (Note - the tags as script stuff changed in 901. So if you are still on 900, your line number may be different.) On line 417 you will see #mailbody# as a variable, tabbed over. Simply remove the tabs. Here is a slice of the file:

Quick note - the white space did not render perfectly on my blog - so you will just have to imagine that mailbody is the online code all the way to the left.

<cfmail attributeCollection="#tagAttributes#"> #mailbody# <cfloop array="#params#" index="mailparam"> <cfmailparam attributeCollection="#mailparam#"> </cfloop> <cfloop array="#parts#" index="mailpart"> <!--- Capture mailpart content into a local variable and delete body attribute ---> <cfif structkeyexists(mailpart,"body")> <cfset var mailpartbody = mailpart["body"]> <cfset structdelete(mailpart,"body")> </cfif> <cfmailpart attributeCollection="#mailpart#"> #trim(mailpartbody)# </cfmailpart> </cfloop> </cfmail>

This fixes it up. You still get some whitespace after the message, but that should be pretty much invisible to the end user. You could remove all the white space if you wanted to, but I thought that was overkill.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA