Best of ColdFusion 10: HTML Email Utility

This post is more than 2 years old.

Welcome to the first installment of my reviews of entries in the Best of ColdFusion 10 contest. If you attended cfObjective last week, then you know this ended up as a good news/bad news type situation. The number of entries were relatively low - 4. The quality of the entries though were high. Personally - I do these contests because I love to see what people build. It's fun. So no matter how many people find the time to participate, I consider it a net win for all of us. With that out of the way, let's look at our first entry, the HTML Email Utility by some dude named Ben Nadel.

If you've ever worked in HTML email, then you are well aware of the serious limitations imposed on you in regards to styling your content. HTML email is so limited it makes IE6 look like a sexy browser. One of the most critical things you can't do in HTML email is supply a style sheet. So instead of having a nice block of CSS declarations, you must use inline style sheets.

Ben's utility attempts to simplify this. You provide it "good" HTML (with a style sheet) and it rewrites it to make use of inline styles. This is done using the jsoup library I mentioned before. It makes use of ColdFusion 10's easy Java library loading to include the bits.

He also makes good use of closures within his processing code. Here's a random sample.

Overall - I think this is an incredibly practical application and something I can see using in the future. Want to try it? You can hit the Demo button below to run it on my server. You can also watch a demo video Ben created here and get the code from his Github repo here.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, 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 https://www.raymondcamden.com

Archived Comments

Comment 1 by Ben Dalton posted on 5/24/2012 at 7:27 PM

Great job on this Ben, I actually remembered this the other day and used it to create a nice html email template. Took all of 3 minutes to download and get started... SUPER helpful.

Comment 2 by Raymond Camden posted on 5/24/2012 at 7:29 PM

I hate to go off topic, but it's my blog, so there...

Ben - your Gravatar is an arcade game. What game is that and is it yours?

Comment 3 by Joe Brislin posted on 5/24/2012 at 10:31 PM

Really nice work Ben! Now you just need to add in a LESS compiler and I'm sold!

Comment 4 by Gary F posted on 5/25/2012 at 2:48 AM

Forgive me, but most email clients work perfectly well with a full stylesheet declared within a style tag in the head section. Outlook, Gmail, Hotmail, etc. I've been doing that for years sending millions of emails (non-spam of course). It's been well tested with not a single complaint. I'm wondering if I've missed the point here?

That's a cool bit of code by the way. (I still don't get closures) It's come a long way from the cfscript I knew from CF5!

Comment 5 by Raymond Camden posted on 5/25/2012 at 4:57 AM

I don't know man - as recently as about 8 months or so ago when I updated the email support for BlogCFC I had to make use of this technique. GMail didn't use any of my <style> block declarations.

Comment 6 by Ben Dalton posted on 5/29/2012 at 5:29 PM

I built a MAME cabinet a few years ago. It was originally a Street Fighter 2 cab. Had a ton of fun building it. Unfortunately I had to sell it when I moved to my current place. I'm going to be building another for my office sometime later this year.

Here's my 7 year old forum post about it: http://forum.arcadecontrols...

Comment 7 by Gary F posted on 5/30/2012 at 3:28 PM

Ray, I'm wrong about Gmail. It does indeed ignore <style> tags. Blast. Maybe none of the recipients realised they were missing pretty formatting as it's perfectly readable without any. At least you've made me aware of this now!

Comment 8 by Raymond Camden posted on 5/30/2012 at 3:32 PM

I can't remember the name, but there IS a service out there that gives you mail previews of your mail for all the major services. I can't remember the name, but it looked like a super-useful service for testing stuff like this.

Comment 9 by Thilo Hermann posted on 6/1/2012 at 3:18 PM

There are some email testing services around, but you probably mean Litmus http://www.litmus.com

Comment 10 by Thilo Hermann posted on 6/1/2012 at 3:21 PM

or try http://litmus.com without www

Comment 11 by Raymond Camden posted on 6/1/2012 at 5:22 PM

That was it - thanks.

Comment 12 by Gary F posted on 6/2/2012 at 12:36 AM

Ooh, gold! Thanks Thilo and Ray. Litmus even shows previews on 8 different mobile clients. This is so clever! Love it. Is it worth $50/month? If you can do all your testing in that time then yes, definately.

Comment 13 by Gary F posted on 6/2/2012 at 1:02 AM

Litmus let me download 101 full size screen shots from countless email clients for free. The only clients that fail to support <style> tags are Gmail and Hotmail. I'm impressed that Yahoo worked well and even an ancient version of Lotus Notes (6). Blackberry, Win Phone 7, Win Mob 6, Symbian 6, iphone 3, all good.

So it's just Hotmail and Gmail that are the big let downs. Booo!