While working on a project at work, I started to see some weird things coming across in an e-mail that the system is supposed to send out. There have been several other developers working in the code, and it had not quite reached the testing phase just yet. Since I had some time on my hands, I started looking into the issue.

When the e-mail went to a GMail address, we were seeing horribly formatted text, instead of HTML. We send our e-mail out as multipart-mime, with both HTML and text versions. I looked at our top 4 webmail domains for all e-mail addresses in our system, and it turns out that AOL mail had the same problem. Yahoo and Hotmail both rendered the HTML.

After digging into the problem, it turns out that if you send multipart-mime, the MIME spec states that the parts closest to the end are closest to the true format. We were sending HTML first, followed by the text/plain version. Flipping the order caused the HTML to appear just fine in GMail / AOL. Here is where I finally found my answer:

Systems should recognize that the content of the various parts are interchangeable. Systems should choose the “best” type based on the local environment and references, in some cases even through user interaction. As with “multipart/mixed”, the order of body parts is significant. In this case, the alternatives appear in an order of increasing faithfulness to the original content. In general, the best choice is the LAST part of a type supported by the recipient system’s local environment. – source