I am trying to embed a bunch of small images in an html table which I want to send using MFMailComposeViewController. After doing some search I figured out almost everyone is suggesting "NSData+Base64 by Matt Gallagher" class to encode the photo in Base64encoding and embedding it into html. While it looks to work on iPhone and with some email servers but Gmail and Yahoo do not show the images embedded this way. This problem is mentioned here as well.
I was wondering if anyone has a better solution for this. I don't want to upload photos on the web and put the link in the html code. I would like the image to be attached to the email and show up as an inline image within html text,table,...
This unfortunately cannot be done currently in the way that you desire. Inline images in HTML email use separate MIME parts that are referenced via a content-id from the body of the message. MFMailComposeViewController doesn't give you control over the MIME structure of the message, and doesn't let you add inline referenced content parts.
Embedding image data into <img>
tags as base64 can work on some combinations-- it's partly a function of email client and partly of the browser ultimately used to render it, but as you have noticed, it's not broadly portable.
I'm not sure about adding to HTML, but here's how I add images as attachments:
UIImage *image = [UIImage imageNamed:@"myImage.png"];
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
NSData *data = UIImagePNGRepresentation(image);
[composer addAttachmentData:data mimeType:@"image/png" fileName:@"curse"];
[composer setMessageBody:@"" isHTML:NO];
[self presentModalViewController:composer animated:YES];
[composer release];
Now all you need is to change the body to be HTML and a way to reference the attached image from the HTML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With