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

I use MFMailComposeViewController in iOS to create a new dynamic email address, but I encountered a problem while trying to use inline images.

At first I tried to add the image to base64 encoding, i.e.

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

But I can only see that on the iPad when Outlook / Entourage ignore it, although I see it in the source!

So, now I'm trying to add an image as an attachment and link to it through its content identifier, i.e.

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

But I don’t know how to get cid via code!
When I attach an image using AddAttachmentData , the image is below and actually generates a <img /> using cid!

In addition, this identifier seems to change with each new email. One of them was my first attempt, then I sent another one, and the Content-ID was 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 it is a dynamically generated image, and it needs to sit inside the email template.

EDIT
I'm starting to think that this is impossible. I have been studying for hours, and it looks like iOS will not let you attach an image and a link to it through its CID. Thanks Apple -_-

+6
source share
1 answer

I used the same limitation of MFMailComposeViewController . There is no way in it to get the content identifier (cid) of an email attachment, so there is no way to compose an html email message that refers to the application using img src='cid:...' . Since most email clients ignore data URLs (embedded base 64 encoded images), the best option for composing an html email message with images from an iOS application is to post images on the Internet and link to them as img src='http://...' . Most email clients will ask the user for permission to download images, so this is not ideal, but apparently this is the only option in iOS that uses public APIs.

+2
source

Source: https://habr.com/ru/post/888496/


All Articles