Skip to content
Swizec Teller - a geek with a hatswizec.com

The most frustrating debugging experience I've had all year

Building emails sucks.

Last week I was tasked with a project. "We're rebranding, our emails were built 3 years ago and they look janky. Let's rebuild!"

"OK I can do that. But emails suck so I'm def not building that shit from scratch"

Our designer built an email template in BeePro. Visual email builder, exports to HTML, promises that everything will work on all email clients, on both web and mobile, and look good no matter what you do.

Wonderful. Look at us being a responsible team and avoiding all the hard finicky stuff.

I look at the template and think "Ok, central body area, some optional pre_body stuff, some optional post_body stuff. Body made out of a few basic widgets."

To avoid bloating up our codebase and make it easier to build many different emails that look just like this, I cut it up into a few Ruby on Rails partials. A basic layout for the email with hooks for pre and post body stuff, a header partial, a title partial, an information row partial, stuff like that.

All my partials were built through careful copy and paste. Inspect the exported HTML, cut out a relevant section, fill dynamic info with erb. Easy peasy.

Here's what the emails looked like in my test environment. Opening as a browser tab instead of sending via SMTP. ๐Ÿ‘‡

And here's what that same email looked like in GMail when my QA team tried it out.

...

Ok, breathe, zennnnn. We can fix this.

The problem is that BeePro builds weird HTML that I had to tweak a little and that email clients take out some of your CSS. Sometimes they tweak HTML to make it more correcter.

You see BeePro doesn't think in boxes like you and I do. It thinks in full width divs and fakes containers.

BeePro fakes containers

Tweaked a few things, moved some CSS around, copy pastad some more HTML. Fixed the email yay!

Looks great in GMail on the desktop. Surely it's fine everywhere.

Now here's the thing, you can't inspect elements in the GMail app on your phone. You can't even tell what's rendering, why things are doing what they're doing, or where any of the elements are.

A-ha! I'll open GMail on my computer, set my viewport to iPhone size, and debug that way! Modern web development tools to the rescue. Huzzah ๐Ÿ’ช

GMail is too smart

GMail is too smart

Nope. GMail sees it's running in web mode and scales down your email instead of forcing it to reflow. I don't know how, but it does. Email looks like the desktop version, just smaller.

Luckily I'm an old skool web developer. We didn't have tools when I started. I know how it goes!

Back when PHP scripts returned a blank screen, if you had an error. Because showing errors on the web leads to security issues, you see. Back when browsers didn't come with developer tools until someone built FireBug for FireFox.

Fun times.

Those arcane skills came useful once more.

In a nutshell ๐Ÿ‘‡

  1. Guess which element is a problem
  2. Add a border
  3. Send email
  4. Check on phone
  5. Refine guess, goto 1

1px solid red is always my first try. Then I move on to blue and green and dotted and dashed and all sorts of things until I understand how things are rendering and why. Each time you tweak some CSS, some HTML, and move things around.

When you're inspecting paddings and margins, you opt for pink and blue and white backgrounds. Background for the big div, background for the small div, hey presto margins and paddings show up. yay

Sometimes you take things out to see if they're pushing stuff around. Binary search through the HTML tree to see which line is causing problems.

It took me 57 iterations. Here's a gif. Enjoy ๐Ÿ‘‡

I may have lost my sanity, I may have begged on twitter for a bullet to the head, but by joe I got it done. The email is damn well perfect.

Now watch as I walk into work this morning and QA says it doesn't work.

Did you enjoy this article?

Published on August 28th, 2018 in Technical

Learned something new?
Want to become a high value JavaScript expert?

Here's how it works ๐Ÿ‘‡

Leave your email and I'll send you an Interactive Modern JavaScript Cheatsheet ๐Ÿ“–right away. After that you'll get thoughtfully written emails every week about React, JavaScript, and your career. Lessons learned over my 20 years in the industry working with companies ranging from tiny startups to Fortune5 behemoths.

Start with an interactive cheatsheet ๐Ÿ“–

Then get thoughtful letters ๐Ÿ’Œ on mindsets, tactics, and technical skills for your career.

"Man, love your simple writing! Yours is the only email I open from marketers and only blog that I give a fuck to read & scroll till the end. And wow always take away lessons with me. Inspiring! And very relatable. ๐Ÿ‘Œ"

~ Ashish Kumar

Join over 10,000 engineers just like you already improving their careers with my letters, workshops, courses, and talks. โœŒ๏ธ

Have a burning question that you think I can answer?ย I don't have all of the answers, but I have some! Hit me up on twitter or book a 30min ama for in-depth help.

Ready to Stop copy pasting D3 examples and create data visualizations of your own? ย Learn how to build scalable dataviz components your whole team can understand with React for Data Visualization

Curious about Serverless and the modern backend? Check out Serverless Handbook, modern backend for the frontend engineer.

Ready to learn how it all fits together and build a modern webapp from scratch? Learn how to launch a webapp and make your first ๐Ÿ’ฐ on the side with ServerlessReact.Dev

Want to brush up on your modern JavaScript syntax?ย Check out my interactive cheatsheet: es6cheatsheet.com

By the way, just in case no one has told you it yet today: I love and appreciate you for who you areย โค๏ธ

Created bySwizecwith โค๏ธswizec.com