Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Content-ID of attached image when composing a new email in iOS

I'm using the MFMailComposeViewController in iOS to create a new dynamic email but have run into an issue when trying to use inline images.

I first tried adding the image as a base64 encoded string, i.e.

<img src="data:image/png;base64, blahblahblah" /> 

But I can only view that on the iPad while Outlook/Entourage ignore it even though I can see it in the source!

So now I'm trying to add the image as an attachment and link to it via it's content ID, i.e.

<img src="cid:BF6E8B41-4D74-419E-B55E-8F18A07381AE" id="BF6E8B41-4D74-419E-B55E-8F18A07381AE" width="509" height="220">

But have no clue how to get the cid through code!
When I attach an image using AddAttachmentData, the image goes to the bottom and actually generates an <img /> tag with the cid!

Additionally, this ID seems to change with every new email. The one above was my first try, then I sent another one and the Content-ID changed to

<img src="cid:59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" id="59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" width="509" height="220">

The reason I have to do this is because this is a dynamically generated image and it needs to sit inside an email template.

EDIT
I'm beginning to think that this isn't possible. I've been researching for hours now and it looks like iOS won't let you attach an image and link to it via its CID. Thanks Apple -_-

like image 520
Marko Avatar asked May 19 '11 03:05

Marko


1 Answers

I've hit the same limitation of MFMailComposeViewController. It exposes no way to get content id (cid) of an email attachment, so there is no way to compose an html email message that references the attachment via img src='cid:...'. Since most email clients ignore data urls (inline base 64 encoded images), the best option for composing an html email message with images from an iOS app is to host the images on the web and reference them as img src='http://...'. Most email clients will ask the user for permission to download the images, so this is not ideal, but it's apparently the only option in iOS using public APIs.

like image 185
Rod Avatar answered Oct 16 '22 18:10

Rod