Reputation: 8414
I'm using MFMailComposeViewController in the iPhone SDK to bring up the mail dialog to send an HTML formatted email. The contents of the message body is being read from an HTML file which is generated in the app and saved on the filesystem. The email looks fine in the send mail dialog and all of the CSS formatting is there. However, after sending the email to gmail and hotmail accounts, the email appears in plain text with all formatting gone. The mail is being sent from my phone using a gmail account.
When I set the message body on the controller I set isHTML to YES. The contents of the html file is very basic; a style block with some CSS defined, and some div containing text. The html file does contain html, head, and body tags (I've also tried it without these tags with just the style and div tags).
Any ideas guys? Been trying to figure this out for close to a day non-stop.
Here's the email window showing the email formatted correctly before sending: alt text http://img515.imageshack.us/img515/7962/screenshot20091031at114.png
Upvotes: 3
Views: 7325
Reputation: 11777
All styles must be put into inline tags or embedded stylesheets in order for CSS to stick.
Think of it this way, if you're sending a message that's formatted from your iPhone, it's got the CSS file local. When you send the email however, that CSS file is gone.
Either putting the CSS in the head or on each tag itself with style=""
will work.
Reference: http://www.htmlgoodies.com/beyond/css/article.php/3679231/How-to-Create-Great-HTML-Emails-with-CSS.htm http://kb.mailchimp.com/article/top-html-email-coding-mistakes/
Upvotes: 0
Reputation: 3955
I confirm that including the STYLE block inside the BODY block seems to work.
Upvotes: 0
Reputation: 51
Including the <STYLE/>
in the <BODY/>
of your HTML should do the trick.
Upvotes: 5
Reputation: 1
We had a similar problem. Couldn't figure out who's stripping the html and why, but we discovered that adding a <font>
tag (yes, the ancient deprecated one) leaves the content type as text/html and includes the full formatting.
Can anyone shed more light one this?
Upvotes: 0