Tim Cracked The GMail - CFMailPart Puzzle!

Posted August 24, 2006 at 1:44 PM

Tags: ColdFusion

My main man, Tim, just cracked the puzzling way that GMail handles multi-part emails. As I had posted before, if you send an email to GMail with a rich text (text/html) part and a plain text (text/plain) part, GMail would always ignore the richly formatted text part and show the plain text. It turns out, as Tim, shows me, the order of the CFMailPart tags are important. In all of my examples, I always put the text/html part first:

 Launch code in new window » Download code as text file »

  • <cfmail
  • to="liz@campus-cutties.com"
  • from="emy@campus-cutties.com"
  • subject="Great Photo Shoot!">
  •  
  • <!--- Send rich formatted part. --->
  • <cfmailpart type="text/html">
  • Hey Em, you looked <strong>red hot</strong> sexy
  • at the photo shoot today!
  • </cfmailpart>
  •  
  • <!--- Send plain text part. --->
  • <cfmailpart type="text/plain" wraptext="60">
  • Hey Em, you looked pretty at the photo shoot today!
  • </cfmailpart>
  •  
  • </cfmail>

This worked for most email clients, but for the increasingly popular GMail, it would only show the plain text part! Well, as Tim pointed out, if you switch the order of the mail parts:

 Launch code in new window » Download code as text file »

  • <cfmail
  • to="liz@campus-cutties.com"
  • from="emy@campus-cutties.com"
  • subject="Great Photo Shoot!">
  •  
  • <!--- Send plain text part. --->
  • <cfmailpart type="text/plain" wraptext="60">
  • Hey Em, you looked pretty at the photo shoot today!
  • </cfmailpart>
  •  
  • <!--- Send rich formatted part. --->
  • <cfmailpart type="text/html">
  • Hey Em, you looked <strong>red hot</strong> sexy
  • at the photo shoot today!
  • </cfmailpart>
  •  
  • </cfmail>

... such that the text/html part is second, GMail will indeed show the richly formatted version! This continues to work in MS Outlook as well. Thanks Tim, you just rocked my world!

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




Reader Comments

Ed
Nov 24, 2006 at 7:08 AM // reply »
18 Comments

cfmailpart should be great, but then along comes blackberry and a client using Eudora 3.1 and all the rules go out of the windows because neither of those clients handles the mailpart tag correctly. i'm royally stuck now because our client is desperate to use HTML but some of the users just can't see it. Know any workarounds?


Nov 24, 2006 at 9:54 AM // reply »
6,516 Comments

Ed,

While I do not know this for a fact, I heard someone one time talking about this type of issue. I think they came up with a solution that they put in the plain text content right into the emails (as if there were no parts) and then put a CFMailPart for HTML emails at the end. For clients that couldn't handle the mail part, they saw the text version and then clients that could handle it (and HTML emails) saw the HTML version.

Of course, I have NOT TESTED this, so take it with a grain of salt.


Ed
Nov 24, 2006 at 10:07 AM // reply »
18 Comments

Thanks for the quick response Ben, I just tested the theory and it didn't work in Eudora. Then again we're talking about a main client so old that it predates any modern standards for emails! Oh well, I'll keep trying. Thanks again for your help.


Nov 24, 2006 at 10:10 AM // reply »
6,516 Comments

Ed,

Is there anyway from the email address to tell if the user is using Eudora? If that is the case, you actually just send a different email to those users.

If not, I am out of suggestions. Sorry.


Ed
Nov 24, 2006 at 10:12 AM // reply »
18 Comments

I wish! :-)


Dec 31, 2007 at 1:57 PM // reply »
1 Comments

Excellent... If I weren't primarily a Gmail user, I probably wouldn't have even noticed this annoyance. Thanks for posting this for the Google spiders to find. :)


Ed
Aug 19, 2008 at 12:03 PM // reply »
1 Comments

This helped me make an internal page, emailing the result to Groupwise. I had the html part first originally and text part second. The emails I got were showing up fine in html format but it had this wierd attachment part.001 which was the text portion.

By switching the order and making the text first, it still achieved what I wanted, which was to show the html part first with no attachments and then also have a text part if the user was viewing text only


Mar 17, 2009 at 11:31 PM // reply »
1 Comments

One more scenario for fun:

If you have a cfmail tag with one cfmailpart in it of type HTML - Gmail renders empty text, noice!


Mar 18, 2009 at 8:06 AM // reply »
6,516 Comments

@David,

Ugg, that is lame. I wonder, do we even care about plain text emails anymore. The only thing I could ever think about was something like a Blackberry. But I assume that by now, even the Blackberry has rich text email capabilities?


Nov 4, 2009 at 1:13 PM // reply »
2 Comments

So, no one is using the type="html" attribute of the cfmail tag? Not enough control?


Nov 4, 2009 at 1:21 PM // reply »
6,516 Comments

@Mik,

I use the type="html" most of the time. I only worry about this when I have a non-html version to offer (which, I spend less and less time worrying about).


Nov 4, 2009 at 1:45 PM // reply »
2 Comments

True enough.


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 21, 2009 at 6:47 PM
Hal Helms - Real World Object Oriented Development, Sarasota - Day Five
@charlie griefer, Thank you.. ... read »
Nov 21, 2009 at 5:15 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jose Galdamez, Oh heh yeah I didn't paste the whole code. I should have defined the vars -- my bad. It's fixed thou. Thanks. ... read »
Nov 21, 2009 at 4:49 PM
Styling The ColdFusion 8 WriteToBrowser CFImage Output
Great work yet again Ben! Whilst I didn't use this whole code, I copied some of your regex code for a similar problem with the lack of an alt attribute and unescaped ampersands in CFIMAGE for Railo 3 ... read »
Nov 21, 2009 at 1:13 PM
My First ColdFusion Builder Extension - Encrypting And Decrypting CFM / CFC Files
@Ben, Because I am pedantic, I just want to make sure that everyone knows there is absolutely no encryption going on. There is only encoding and obfuscation. The cfencode tool only obfuscates your C ... read »
Nov 21, 2009 at 12:28 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jody I can't seem to get your code sample to work. If you are still having problems, try this code out and see if it gets you what you wanted. <!--- Comma delimited list with various duplicates ... read »
Nov 21, 2009 at 11:03 AM
Groovy Operator Overloading Does Not Work In The ColdFusion Context
Hi Ben, Thanks for this informative post. Now I am reading ur old posts too ... read »
Nov 21, 2009 at 10:56 AM
HostMySite.com Has The Best ColdFusion Hosting
@Mehul, Yes very nice people, however several downtimes per day which was not acceptable. Hence we had to move out. I am glad you are having good luck with them so far. ... read »