WebKit’s HTML in Mail 2.0
As everyone knows, Tiger’s Apple Mail allows you to compose in two formats — Plain Text or Rich Text. You can set your default choice in the Composing preference pane of Mail’s Preferences.
In fact, the text that you enter in “Rich Text” mode is composed and rendered in HTML by WebKit, Apple’s modified extension of the KHTML layout engine that is also used by Safari, NetNewsWire, BBEdit, Growl, Adium and many other apps.
It does things a little differently than its main layout engine rival, Gecko, which is used by Thunderbird, Firefox and the rest of the Mozilla stable. (Wikipedia has a comparison of the major layout engines).
Although I am a “plain-texter” myself, I thought it would be interesting to look under the hood at the way WebKit handles HTML in Mail, and to see what kind of code it produces. If you are interested in that sort of thing too, the results follow the jump.
I began by composing an HTML message in Thunderbird, which has a fully-featured HTML text editor and uses the Gecko layout engine. I sent it off, switched to Mail and retrieved it. It came up nicely in Apple Mail, looking like this

Using the View -> Message -> Raw Source (Shift-Command-U) option in Mail, I could see that the underlying code was nice, clean HTML (except for a font tag mishap which is probably my fault, not Thunderbird’s):

Composing was more awkward because of the limitations of the Rich Text editor in Apple Mail. Using the “Message is raw HTML” option provided by the MailPictures plug-in, I was able to cut and paste the HTML from the Thunderbird message into the Apple Mail Compose Window, and then send and receive a message that was rendered in just the same way. The underlying HTML code was also the same.
Using Mail’s native editor to compose the message, I was able to produce an email that looked the same, except that there is no way to format bulleted lists. But the code underneath was quite different:

A more practised eye will see more interesting things, but I was struck especially by the use of non-standard, khtml-specific attributes and classes inside the tags like khtml-nbsp-mode and khtml-block-placeholder.
I don’t know what to make of this experiment. I lack the skills to take the comparison further. But clearly, entering raw HTML via the MailPictures plug-in generates the cleanest HTML messsages, able to be read by the widest variety of email clients. A look at the code underneath Apple’s own HTML mail-outs shows that they don’t use Apple Mail or WebKit to make them.
Two questions remain in my mind,
- What is the benefit to Apple and its users of producing HTML coding like this? How is it better than the HTML Gecko generates?
- What is an Apple-style-span? How does a non-Apple email client, say Outlook, know how to render it?
Perhaps there is something blindingly obvious about this that I am not seeing.
Similar Posts:
- Re-sending HTML messages in Apple Mail
- Setting an HTML font tag in a Mail.app message
- WebKit nightly builds now offer Gmail rich text
- Sending HTML messages in Apple Mail
- Composing HTML messages in Apple Mail
No tags for this post.

October 26th, 2005 at 7:03 am
[...] 3, 20. Greater HTML control. MailPictures enables the entry of raw HTML into your emails. Granted, the end results of WebKit’s HTML rendering are unusual, but it can be done. [...]
December 15th, 2005 at 8:56 am
[...] I can’t get my head around how Mail.app renders HTML via WebKit at all, so I am willing to listen to anyone who does. Technorati Tags: Apple Mail, Mail.app, Outlook, HTML, WebKit [...]
December 26th, 2005 at 8:44 pm
[...] Filters for creating a Global Inbox. Compared to Mail.app, its IMAP implementation and support for composing in HTML using the Gecko engine are better without a doubt. [...]
January 4th, 2006 at 7:49 am
As an alternative, what I have found to work is to code my pages standards compatible in BBEdit (with the one exception that positioning elements almost never work in other mail clients, so sad to say, tables where the only option; and all css styles have to be inline, since many web based clients strip out the head of the HTML). Then I load that page onto my web server, in safari I open and choose:
File > Mail contents of this page
This usually now adheres to my html requirements with a few webkit codes at the top.
I would agree that it makes no sense, mail should follow safari’s guidelines, especially now that safari is Acid 2 ready to go. But email html is always an uphill battle, from horrible output in the likes of hotmail, yahoo mail, and outlook/IE in general.
January 4th, 2006 at 11:28 am
Hi Brady. Thanks for all the comments and the useful points in them. I’ve installed the “Recent Comments” plugin in your honour! :-)
That’s a good tip. I’ll try that out myself next time there is no way around an HTML email.
June 20th, 2007 at 12:17 am
Why Apple doesn’t provide a good mail editor such a s Outlook? M$ integrates Word into Outlook to do that, Apple could use Pages for that matter in the future… what do you think?
June 20th, 2007 at 12:57 am
I’m a plain text kinda guy myself, so I’m probably not the best person from whom to get an opinion on this. :)