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



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

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 »
5,406 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 »
5,406 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 »
5,406 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?


Post Comment  |  Ask Ben

Recent Blog Comments
Jul 4, 2009 at 4:00 AM
Terms Of Service / Privacy Policy Document Generator
thanks ben, I'm not a big fan of contracts so to find your no no-nesense ToS generator has helped me no end. all the best matt ... read »
Justice
Jul 3, 2009 at 11:10 PM
Create A Running Average Without Storing Individual Values
@Ben, I think you're going about this the wrong way. You're trying to use complicated techniques when there is a simple and beautiful technique readily available (a la Gary Funk's comment). Instead ... read »
Bob
Jul 3, 2009 at 9:19 PM
Project HUGE: Huge In A Hurry - Get Big - Phase 3 / Week 1
a good technical explanation http://crossfitphoenix.typepad.com/crossfit_phoenix_forging_/the-overhead-squat.html ... read »
Jul 3, 2009 at 9:03 PM
Create A Running Average Without Storing Individual Values
If I wanted to do this and only carry two numbers, I'd keep track of the sum and N. Then you are pretty much accurate all the time. average = (sum + new_number) / (N + 1) But all this was in a for ... read »
Roland Collins
Jul 3, 2009 at 8:58 PM
Create A Running Average Without Storing Individual Values
@Martin - not just floating point though. Depending on what langauge you're working in, decimals can cause just as many headaches if they're not precise enough. But again, for most applications, th ... read »
Isnogood
Jul 3, 2009 at 7:16 PM
Project HUGE: Huge In A Hurry - Get Big - Phase 3 / Week 1
Watch this http://www.nsca-lift.org/videos/default.shtml ... read »
Aaron
Jul 3, 2009 at 7:13 PM
Project HUGE: Get Big, Phase One (Chat Waterbury - Huge In A Hurry)
I've just finished the 3rd week of phase 3, and have to agree that the overhead squats are hard. I think this is most due to the wide grip on which places more pressure on your upper back. Only this ... read »
Isnogood
Jul 3, 2009 at 7:11 PM
Project HUGE: Huge In A Hurry - Get Big - Phase 3 / Week 1
Very good, there were some near perfect reps, and there were some dodgy ones, but you're getting there your body position is good. Work on your depth and do not let the bar move forward or backward, ... read »