Showing posts with label Email Building. Show all posts

Continuation > Collapsible Email

by Developer @ pebbl.co.uk on Saturday, 24 September 2011

I didn't quite get round to finishing my original post about this, it was just at that time that work went a little hectic, and I don't think I've properly stopped since.


Anyways at the time the information was fresh in my memory, it's gone a little stale now unfortunately. I remember there were quite a few things I wanted to write about, so if I do get some spare time (and a reason to look in to it) I'll pick up my collapsible email template again. Before I consign this to the "most probably never" however, there are a few things that I can remember that may help out other people trying to get around particular mail agent inconsistencies.


Outlook 2007/2010


Next to Lotus Notes, Outlook 2007 is almost fun... but compared to the other e-mail clients, it is quite simply a joke. Annoyingly it is a joke that is installed on a large number of machines worldwide. So as per usual, us developers have to find some way of limping on with awful software. In case it helps, here are a few nice style properties, that affect only microsoft products.


mso-hide

If you need to hide a particular element only in Outlook 2007/2010 use the following inline style.


style="mso-hide: all;"

It should work just like display:none; but is Microsoft specific. I've mainly used this on items that really are already hidden, but in some cases their presence still creates padding or spacing issues for Outlook.


mso-table-lspace and rspace

Whilst trying to get my collapsible email to layout nicely I kept getting annoying horizontal spacing appearing between tables in Outlook. Eventually, the only way I could find out what was actually causing it was to send my email to my Outlook 2007 account and grab the raw message content / source. Obviously for most email clients you would assume - logically - that the raw message source would be the same as the e-mail i sent out. As usual though Microsoft do their "magic" and translate the mark-up in to bloated gibberish that is barely recognisable as my original.


After poring over the source for a while I spotted two additional style properties in amongst all the nonsense things that were being dynamically generated. These were "mso-table-lspace" and "mso-table-rspace". Don't ask me why Outlook 2007 thought it prudent to add them, my only guess would be that because the HTML renderer used by OL2007 is primarily designed as a WYSIWYG interface, this extra spacing is added to allow users to click between tables and type content. This however makes no sense from the context of "viewing" an e-mail, so my assumption is that I am 100% correct... Thankfully these properties are not automatically overridden, so all I had to do was specify them on each of my tables, and set them to 0pt.


style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;"

Collapsible HTML Email and Outlook

by Developer @ pebbl.co.uk on Monday, 6 June 2011

Have you every tried building a pixel perfect HTML email that works across a range of destination user-agents?

If the answer is yes then you'll know just how frustrating it can be - especially when you include the likes of Lotus Notes (6.5.4) and Outlook 2007/2010. If no, then it's probably only a matter of time, but I wish you luck in avoiding the problem... :)

Now usually - at my company - we stick to a rather rigid design ethic in order to minimize the problems we'll undoubtedly encounter when trying to build complex layouts for these archaic systems. But the other day we had a request from a Designer who wanted to create a layout that would work across all the usual agents we support (which already includes mobile devices) - but he also wanted the layout to keep it's readability on mobile devices without the need for zooming.

Obviously this is achievable, but it's only achievable using a collapsible template (something we usually employ for websites) and then only using quite modern (but degradable) standards. This causes two problems for email:

  1. Email is anything but modern - most popular user-agents are at least 5 years old now (if not more).
  2. Pretty much the only way to achieve a pixel perfect design in an email is to use tables - and tables are anything but "collapsible" or "degradable".

If at first...

Undeterred by the possible problems, we set about testing different ideas, and just experimenting with the different user-agents at our disposal. Initially everything was far too easy, we almost "seemed" to have a layout that worked in the first 30 minutes, using only the old HTML Table attribute "align" and using separate tables like "cells".

The following example shows two separate tables aligned using align="left"

Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Now the same code, but forced to wrap at 200px across, as you can see the layout collapses to the parent's width - which is exactly what we needed

Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

So the above handled the collapsing behaviour we needed, but we also required the ability to create "rows" from these left aligned tables. If we just put a whole load of left aligned tables together, they would all wrap along side each other, not really creating the most typical of email layouts... :) So the most obvious way of achieving this was to do what we would normally do in a HTML Email... wrap the aligned tables with another table.

The following shows aligned left tables that would all float in a line, if it weren't for the outer wrapping tables acting as the "row" part of our structure (creating a 2x2 grid).

Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras dignissim porttitor eros non rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

The above all seemed to work perfectly - mainly in Mac Mail, Win/Mac Thunderbird, Internet Explorer, FireFox, Opera, Chrome and Safari and even Entourage (these being the quickest and easiest to test in). But then, as usual, the respective rugs were pulled out from underneath ourselves once we tested the layout in Outlook 2007.

... you don't succeed?

Whoever thought it would be a good idea to use the Microsoft Word WYSIWYG HTML Engine to render HTML Emails in Outlook 2007 and 2010, must have been mad, lazy, lost or ever-so-slightly confused (delete as appropriate). It causes no end of rendering problems for developers, usually with random and inexplicable sizing calculations or padding problems.

Anyway - complaining aside - it took a little while to work out but it seemed there were a few issues befalling the layout in Outlook:

  1. Outlook 2007 automatically shrunk any table with no width set to the smallest width it could have. This obviously affected our outer tables (our "rows") as these only work in a collapsible design if we don't specify a width. This idea had worked in everything save for OL2007 which just ended up auto-collapsing our structure to it's minimum width (rather useless).
  2. Our aligned tables did line up as we'd hoped, but there seemed to be inexplicable horizontal spacing (what a surprise!) of about 10px between each table - pretty much useless for a pixel perfect design.
  3. There also seemed to be about 10px of vertical space between each group of aligned tables (our "rows").

So after the usual trial and erroring we managed to solve the above problems (almost).

  1. Rather than relying on outer tables to create our "rows" we had to remove any non-dimensioned tables. Instead we used a more web page based approach by using a page break with clearing set to "all" (the value of "both" failed to work in OL2007). This introduced another problem, yet more vertical space between each "row". This was fixed by wrapping the <br clear="all"> tag with a <font> tag with it's size and line-height all set to 0.