My solution for sending messages via email on the iPhone – detailed here – works for every mail client… except Gmail.
Gmail simply will not let you see embedded images. Period.
Since this kinda crap really grates on my nerves, I started digging a little deeper. Plus, I really think there should be a 100% universal way to attach stuff to email messages from the iPhone… and I’m not the only one. My embedded images solution is workable, but is not wholly satisfying – because it is not a 100% solution.
So, like I usually do when trying to sniff out how a particular piece of web software works without having access to the source, I see what is being sent “over the wire.” And since I knew that iPhoto on the iPhone WAS able to send an attachment, I sent myself a picture… and then checked the raw message source to see how Apple was doing it.
I sent myself a picture, with no accompanying text, and this is what the “interesting” pieces looked like:
X-Mailer: iPhone Mail (5H11)
Mime-Version: 1.0 (iPhone Mail 5H11)
Date: Wed, 11 Mar 2009 12:13:43 -0400
Notice the Content-Type of “multipart/mixed.” No real surprise there… just that when you send a message using the Email client launched by an iPhone application, this is almost always “multipart/alternative”. First “hmmm.”
Secondly, when I used my methodology of using embeded images (<img src=”data:image/png;base64[my data here in base64]”>), this gets cobbled out as
by the Apple Email Client. By contrast, Apple creates it’s image attachments by doing the following:
So – why not just do the same thing?
I don’t know what MIME boundaries (the “Apple-Mail-1-782786827” above) Apple is using to segregate its constituent email pieces (text, html, images, attachments) ahead of time – and they are generated dynamically by the email client when putting together it’s messages.
If I knew what the boundary tag was, I could fake out the client, create my own inline image, and boogey on down.
Now, even though this does seem like a serious roadblock, it may not be a total loss, because it presents both
- (a) a possible direction to look (fake out a boundary, unlikely though it may be) and
- (b) it presents another solution path (go down to the socket level and code my own SMTP alternative, so that I can create the MIME code directly to send out my attachments).
(a) looks to be a total non-starter, as it looks like the boundary is made – in part – of a timer component, and there is no way to guess how long someone will keep the message open before sending to reliably fake this out each and every time. (b) will absolutely work – provided you are motivated to write this dude. Looks like a commercial opportunity for a Cocoa Touch class, and I may yet do this.
A final and as yet unspoken work around would be to know how Apple preps an image in their email client before sending, so that it’s Mail.app knows to wrap the image up as an inline attachment. Unfortunately, I don’t know of anywhere I can look to see how they compose their messages (no view source – dang!).
All in all, this has stimulated me to investigate some additional paths for a problem that I thought I had a reasonable solution for – and for many, I do and did.
Onward and upward.