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

1

6

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 -_-

Akela answered 19/5, 2011 at 3:9 Comment(0)
W
2

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.

Wolsey answered 13/4, 2013 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.