Oct. 1, 2013, 8:49 a.m.
IT

iPhone not displaying multipart/mixed emails

I have recently had to write an application that sends out emails with attachments. This is not a hard thing to do, as is evident from the multipart/mixed RFC. My initial attempts worked perfectly when receiving the email via Apple's Mail.app. However, on the iPhone and iPad these emails rendered with the body text:

This message cannot be displayed because of the way it is formatted. Ask the sender to send it again using a different format or email program. multipart/mixed

No body text and no attachments showed up. Naturally I tried to search for the issue to see if other people experienced the same problem. Some people did. However either there were no solutions to the questions or the responses were your typical non developer users who has no better recommendation than to "reboot the phone".

I decided to send myself an email with an attachment using Mail.app and compare the raw source with what my program created. They looked identical. Here is the basic structure of a multipart/mixed message:

Content-Type: multipart/mixed; boundary="XXX-mixed-3538f37d942f9f90112c636a0dc200ec"
From: someone@somewhere.com
Subject: Some subject.  


--XXX-mixed-3538f37d942f9f90112c636a0dc200eb
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii

Hi internet,

This is a simple mail body text.

Bye!

--XXX-mixed-3538f37d942f9f90112c636a0dc200eb
Content-Disposition: inline;
    filename=File.pdf
Content-Type: application/pdf;
    name="File.pdf"
Content-Transfer-Encoding: base64

QlQgL0YyIDcuMDAgVGYgRVQKcSAwLjA3OCAwLjA3OCAwLjA3OCByZyBCVCAyNTQuMDYgNDguOTIg
....
IDAgUgovSW5mbyAyMCAwIFIKPj4Kc3RhcnR4cmVmCjUxOTA1CiUlRU9GCg==

--XXX-mixed-3538f37d942f9f90112c636a0dc200eb--

This is correct - this matches with the guidelines of the RFC. Eventually I spotted the problem. It was not the formatting of the mail body, it had to do with the headers. This was shown implicitly in the RFC, but never elaborated on as a requirement.

Adding this to the header resolved the issue and the mail shows up perfectly on iPhone and iPad:

Mime-Version: 1.0