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

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

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.

Related

How to display images within html email content in gmail?

In yahoomail and html email, the images are loading but not in gmail. I observed that in gmail, the image urls are altered.
For example,
Image URL in yahoo/Hotmail : http://qaecmwcs.qacorp.moneygram.com/sites/Satellite?blobcol=urldata&blobkey=id&blobnocache=true&blobtable=MungoBlobs&blobwhere=1515690635784&ssbinary=true
Url for the same image in Gmail : https://ci5.googleusercontent.com/proxy/2B2Fyk0aboH-eiikaxVWdIC9DXbJzhZEuWKm5yPwUeXf3SdYRuoKBGT-HeCFRlNcg7VTzljtSsEhHkikFMGPac35C6Az2Fc2wsdig3xj0S3g1bEIABaMx9RKnTjYuqagP1hUGNl3GG4f2aHy26wHrINZkdn5Wv3y6zcvbWHUL8rabUcjHuCO05i8RM31x8iFJmUorccqIJM6P9f6-eLIaQ5GpZYCrKPJws72HfM2-AsXcg=s0-d-e1-ft#http://qaecmwcs.qacorp.moneygram.com/sites/Satellite?blobcol=urldata&blobkey=id&blobnocache=true&blobtable=MungoBlobs&blobwhere=1515690635784&ssbinary=true
When I manually remove the additional url part in the image src,from DevTools then I am able to see the image. Can any one please let me know how I can handle this in gmail?
If you want an image to work in email, it has to be viewable by your audience. The image path should be straightforward and simple. What you have posted over and over in your questions are images that are not accessible to the general public, so they will never work for an email.
Image Path
This is how an image should be formatted:
<img src="staticpath" alt="imagename" class="imageclass" />
<img src="https://www.w3schools.com/images/w3schools_green.jpg" width="104" height="142" alt="W3Schools.com">
<img src="https://placehold.it/600x600" height="600" width="600" />
More information:
https://www.w3schools.com/html/html_images.asp
Image Descriptors
As a best practice, an image path should end in a descriptor that defines what the format of the image. Images that work well with emails include .jpg .png .gif.
More Information:
https://litmus.com/blog/png-gif-or-jpeg-which-ones-should-you-use-in-email
Email Templates
Your email templates should follow the basic practices of a well-formatted html page. Email development is not Web development because email clients do not support current html 5 or css 3 standards. So it can be very hit and miss to create a complex email.
The following email templates will give you a good idea how an email should be created, how images should look, how image classes work.
Email template Examples:
http://tedgoas.github.io/Cerberus/
https://foundation.zurb.com/emails/docs/v1.0.5/index.html
Please take the time to read through this answer, read through the attached examples.
Best Practices & Considerations when writing HTML Emails
Good luck with your images.
The firewall was blocking the images from displaying. When client opened the firewall then the images within the server are loaded.

How to Include image in email using sails email hook

Sails version: 0.12.14
sails-hook-email: 0.12.1
I am trying to send image in the email so that I can show in the email, and below is the code,
Note: I don't want to send it as an attachment, but want to show in the html.ejs page itself (i.e. in the email itself).
views/emailTemplates/forgotPassword/html.ejs
<p>Dear <%=recipientName%>,</p>
<br/>
<img src="/images/img1.png" width="300">
But it is not visible in the mail.
So how to include the images from assets/images folder to the above html.ejs file and make them visible in the mail that we send.
Please help me.
If your app is available on the internet, you can do that just by giving the making the src attribute absolute instead of relative. Something like this:
<img src="http://mywebsite.com/images/img1.png" width="300">
If your app is just on localhost or not online, then this won't work. The only solution then is to "embed" them image, which some email clients will display as attachments.
Note that some clients may show a "blocked remote content / click to allow remote content" message before they show your image properly.

Can you and how do you embed images in an email when using the Gmail API?

When creating a message and using it to create a draft or email using the Gmail API, can you have an image embedded in the body? I'm looking to have the image data actually embedded similar to how copying and pasting an image (the actual data, not the link) into a Gmail email will place the image right in the content.
Can it be done like this or do I need to upload the image to some other location and use HTML to embed the image in the email? Any pointers on how to do it?
The short answer is that you would do this the same way you would for any email service.
The long answer is that you need to create a multipart/related message, where one part is the HTML content of the email and the other part is the image. The image part contains a Content-ID header that specifies an ID for the image, and the HTML image tag references that ID in the src attribute using the format cid:ID_HERE.
An example of how to construct such an email in Python is here: https://stackoverflow.com/a/1633493
P.S. - A great way to see how emails are constructed is to look at the raw message. You can look at the raw message for a given email in Gmail by clicking the drop down arrow next to the message and selecting "Show original".

Creating image data URI with proper format

I am sending html emails in php.I want to embed images so that images can be viewed directly
i used base64 encoding but it is not working as gmail is not supporting it.
But i received one email and it has image url in this format:
?ui=2&ik=f9790f3715&view=att&th=146e7afa75b55a47&attid=0.2&disp=emb&realattid=10bf591ea0437383_0.1&zw&atsh=1
and it was displayed directly. how is this working? any help please
These are embedded images. You send an image as an attachment and then use it in your img element like: <img src="cid:yourimage.png">. Gmail transforms the "cid" link to its internal file storage link and that's why it gives <img src="?ui=2&ik=..."> element.
This is one of two common ways to have images within email.
The other way is to keep images in your hosting and send img elements with external links: <img src="http://yourdomain.com/yourimage.png">
I strongly recommend to use the second approach especially if you expect to have a lot of images in your email. I had problems with attached images display on Gmail which I couldn't solve.

Email an image via custom url scheme

I am using custom url schemes. I can send string messages as parameters to my custom url and emailing this to any person. When any person opens this email attachment in device in it open my app installed in device with the passed parameters in my custom url.
Similarly how to email an image via custom url and when any person opens this attachment the image is passed to my app in device.
I tried to encode the image in base64 format and tried to append to my url,but not working.
Any ideas??
Thanks in advance
While there technically isn't a limit placed on url length by the standards, in practice, there is (see these two questions here on SO).
My guess is that you're running into that limit.