Posted by TimSlavin at November 11, 2004
Please note this article has been completely rewritten, tightened up, and re-organized on April 12, 2006. It provides lots of information about coding emails to display well in Google Mail and Lotus Notes. A much earlier version of this article was published on SitePoint, a site for web developers and designers, and the reader comments there include additional coding ideas.
Finally, note that I've written a companion article to this one, How To Build a Basic Email Marketing Capability, that describes the business process needed to do email marketing, including how to write html and text email newsletters.
Updates are noted at the bottom of this article if you've bookmarked this page and want to see what has changed.
HTML email newsletters are a big success for publishers and readers. Publishers can track rates for email opens, forwards, and clickthroughs to measure reader interest in products and topics. Readers see information laid out like web pages, in a way that is much easier to scan and navigate than top-down plain text email.
For programmers, however, coding HTML email can be a mix of misery and pain.
The biggest pain is that people use many different software tools to read their email, from desktop software such as Eudora, Outlook, AOL, and LotusNotes to web-based email services such as Yahoo!, Hotmail, and Google Mail. Each of these email software tools can display the same email code in vastly different ways. Even when these tools display an html email properly, readers size the width of their emails from narrow to wide.
This article describes the results of hands-on experiences coding html email newsletters for clients, as well as bits of technical information from the internet.
Determining the layout design is the first step in coding an html email. Single column and two-column layouts work best for emails because they control the natural chaos that results when a lot of content is pushed into such a small space as email.
With a one column layout, typically there is a header that contains a logo and some (or all) navigation links the parent website. Below that are the intra-email links to stories further down in the email. At the bottom of one column layouts are the footer (often with links that repeat the top navigation) and unsubscribe instructions.
Two-column email layouts also use a header and footer. They also typically use a narrow side column to contain features and links to more information. The wider column holds the main content of the email.
Promotional emails follow the same rules but with much less content and links. They often include one to two messages and sometimes one big image with small explanatory text and links below the image.
All of these email layout possibilities can be coded easily with html tables to divide up the space into rows and columns. Using html tables also helps with problems caused by different email software and how they can read the same email code differently.
The basic approach follows these steps in coding the email layout with html tables:
While this approach might offend purists who prefer to code to the latest standards, there are limits. For example, no matter how badly LotusNotes displays html email, resorting to use HTML FONT tags should never be required.
Once the email layout coded as a set of nested HTML tables, the next step is to add in CSS styles. Here are the steps to follow:
So instead of:
style=”margin-top: 10px; margin-right: 5px; margin-bottom: 10px; margin-right: 0;”
use this format (top, right, bottom, left or TRBL):
style=”margin: 10px 5px 10px 0;”
Note that some email delivery services will unpack style definitions to make them more explicit and, therefore, more readable by all email software. For example, the CSS shorthand style=”margin: 10px 5px 10px 0;” can be expanded into the long style declaration shown above. Test each email and look to see what happens to the email code. Start with CSS shorthand because, in the worst case, it appears to work well with all email software.
Coding an html email perfectly is only a partial solution. There are several best practices to follow to ensure the email works well.
With the html email coded as described above, the next step is to test the email in a variety of email software. Often this will identify problems that require workarounds.
The first test tools to use are the Firefox and Internet Explorer web browsers. If the email displays well or perfectly in both browsers, chances are good that testing the email in Outlook, Yahoo!, Google Mail, and other services will reveal only minor problems.
Once the email appears fine in the two web browsers, use an email delivery service to send the email to a range of test email accounts. Ideally this should include accounts with Yahoo!, Hotmail, and Google Mail.
Which test accounts are used, however, should be determined by the domain names in the email address list of people who will receive the email. For example, if there are few or no AOL subscribers on this list, then it may be a waste of time and money to set up an AOL email account.
Here are the most common code tweaks that are found in this test phase:
In addition, the following best practices are recommended:
As part of testing an email, also include a test for potential spamminess. SpamCheck (http://spamcheck.sitesell.com/) is a useful service that highlights issues that might cause the email to trigger spam filters. Note, however, that SpamCheck is a free service offered by a vendor. Purchase of their services is not required to use their spam check service.
Once the html email is tweaked so that it displays well or perfectly in the test email accounts, the next step is to go through a checklist. Verify, for example, that the From address displays properly (as a name, not a bare email address), the subject line is correct, the contact information is correct and visually obvious, the top of the email has the text, “You received this email because … Unsubscribe instructions are at the bottom of this email.”, and so on.
If it is important to know absolutely everything wrong with the html email code, try a service like Browsercam.com. For a small hourly fee, post the html email as a web page on a server, then point Browsercam at the email page. Their service takes snapshots that show how the email appears across a wide range of browsers and operating systems. While they do not show how email software will display an email, some email software use web browser components to display HTML email. And Browsercam provides a highly detailed look at all flaws in the email code, not just the obvious flaws.
Need a Google email address?
I have about 50 free invitations that let me give Google Mail addresses to people. If you need one for testing your email newsletters, just find my email address on the right side of this page (under MASTHEAD, the Email Me link) and send me a request. I'll be happy to help you.
— Tim Slavin
It seems obvious that a new service like Google Mail that is viewed with a web browser would display html email perfectly, with the latest standards. It is not that easy. Because Google cannot control how senders will code CSS and HTML, they have to take steps to ensure their application displays properly regardless of the quality of the html email that is displayed.
As a result, Google Mail is a new webmail service that acts like an artifact of the early 1990s when web standards were primitive. It takes some work, but it is possible to crack open a Google Mail page and see just how convoluted their approach is to rendering html email.
For one thing, Google Mail deletes any CSS style reference to a set of styles, no matter where it appears in the email. And fonts displayed in html tables, the only alternative to using styles, have the odd habit of appearing larger than intended no matter how the html email is coded.
Here are coding techniques that appear to work well in Google Mail and older email software:
Besides Google Mail, another hazard a programmer faces when coding email is less obvious: LotusNotes. Many large corporations continue to support and upgrade their Notes installations. As of 2004, IBM reported that 95 million people used Notes. Unfortunately, it is impossible to tell which companies use Notes. So code html emails as described in this article. The more primitive the code, the more likely it will work well, if not perfectly, with Notes.
That said, it is quite possible that Notes will introduce quirks that beggar belief, for example, converting images to their proprietary format. Or Notes will simply ignore flawless basic html in one email but display other html fine in another email.
Here is what apparently helps Notes display html email:
Many people who receive email prefer HTML over text for any number of reasons. For programmers, however, the task of coding an HTML email appears both simple and horribly complex. Hopefully this article has described many of the issues and coding strategies that work across email software.
What is the best idea to take from this article? If there is a choice to be made between a simple coding solution and a more complex solution, simplicity always works better.
Here are common questions that I receive along with my answers (more will be added later):
Besides this article, these online resources should be very helpful:
MailChimp Weblog
http://mailchimp.blogs.com
An excellent weblog devoted to email marketing, delivery, and coding issues that MailChimp publishes to support their email delivery business. They provide a lot of useful information, tools, free email templates, and links.
HTML Email Tips for Web Designers
http://mailchimp.blogs.com/blog/2006/01/im_a_web_design.html
A useful barebones list of guidelines for creating and sending email. Their free email templates also are great samples to study because their code is heavily commented and has been tested against a broad range of email software. And, finally, their Resources page includes great links to best practices (at the bottom of the page), as well as other resources.
"CSS Support in HTML Emails of Hotmail, Yahoo! Mail, and Gmail" by Xavier Frenette
http://www.xavierfrenette.com/articles/css-support-inwebmail/
This is excellent research and style by style results that show how these three webmail services display CSS.
"A Guide to CSS Support in Email"
http://www.campaignmonitor.com/blog/archives/2006/03/a_guide_to_css_1.html
Campaign Monitor, an email service provider, has taken Xavier Frenette's excellent work documenting CSS performance in a few email clients and expanded it to include Gmail, Hotmail, Yahoo! and Windows Live Mail, as well as for the PC they cover Outlook 2003 and Outlook Express, Lotus Notes, and Thunderbird and for the Mac they cover Mac Mail, Entourage, and Eudora. Their article also includes a link to Optimizing CSS presentation in HTML emails, the follow on article to "CSS and Email, Kissing in a Tree" which is linked below. And a link to another useful article, "Email Design Guidelines for 2006, that shows how to code for your subscribers who use image blocking and/or the email preview pane in their email readers.
"Secrets of HTML Email Series"
http://www.graphics.com/modules.php?name=Sections&op=listarticles&secid=16
Some of this information is old but they have a good piece on Lotus Notes.
Lotus Notes Trial Software
http://www-128.ibm.com/developerworks/lotus/downloads/
Free downloads of their latest software if thoroughly testing an email with the Notes client software is needed.
Browsercam
http://www.browsercam.com
Excellent service for testing how compatible your web pages are with a variety of web browsers and operating systems. For email, it simply shows you all the warts in your html code, even though your email might work fine in Notes, Google Mail, and other difficult email software environments.
SpamCheck
http://spamcheck.sitesell.com
Decent free online service that tells you about the "spamminess" of your email. You also should look for an email delivery service that provides this sort of spam check.
CSS-Discuss: HTML Email and Using Style
http://css-discuss.incutio.com/?page=StyleInEmail
SimpleBits SimpleQuiz
http://www.simplebits.com/notebook/simplequiz/index.html
DadaMail Software
http://mojo.skazat.com/
CSS and Email, Kissing in a Tree
http://www.alistapart.com/articles/cssemail/
An excellent CSS-only approach to html email published by A List Apart. NOTE: The author has written an update to this article, posted at the Campaign Monitor blog, Optimizing CSS presentation in HTML emails.
How HTML Code Affects E-Mail Deliverability
http://www.clickz.com/experts/em_mkt/email_delivery/print.php/3490146
A decent overview that describes how different email services view the html you include in an html email. You can't address every problem directly (for example, creating a clear boundary between the html and text versions of your email is a problem for your email service provider, if you use one) but it helps to know what happens.
MHTML Standard Home Page
http://www.dsv.su.se/~jpalme/ietf/mhtml.html
This site describes one approach to embed your images and links into your html email.
March 23, 2003: First version of this article posted.
November 11, 2004: This article completely rewritten for publication on SitePoint. Small changes and improvements made to this article that could not be done with the SitePoint version.
January 21, 2006: Added details about how to code email newsletters to display properly in Google Mail, also known as GMail. These details are based on a reader tip (from Romania, no less) and extensive testing.
January 26, 2006: Added information about using background images in Google Mail and the need to define fonts carefully within the TD cell and individual tags, for example, the H2, P, and A tags. It's real work to get Google Mail to read your font sizes correctly.
April 12, 2006: Completely rewrote the article, from scratch, incorporating newly discovered information from Xavier Frenette and information from MailChimp about their experiences coding email templates that work with LotusNotes.
May 2, 2006: Added link to MailChimp's Resources page, mostly because of the Best Practice links at the bottom of the page. These are excellent, objective resources on that topic.
May 9, 2006: Addded a link to some excellent reference material ("A Guide to CSS Support in Email") from Campaign Monitor, an email service provider.
May 13, 2006: Added link to ClickZ article that describes how (as of 2005), internet service providers evaluate the html code within html email.
July 7, 2006: Added MHTML information and the anchor tag question at the bottom of the article.
August 30, 2006: Added reader comment about how using background images appears to not work with some versions of Outlook. Be sure to test your email code with your target email software.
Click the red button above or here to read a review of this website posted on Small Business Trends, an excellent resource for business people.
This site is an online magazine that offers free how-to internet knowledge for budget-minded businesses and the designers, programmers, and others who support them. Learn More...
Writer, Editor, Publisher: Tim Slavin
Tel: 480.209.1917 (US)
AIM: redhorsecomm
Est. November 2002