Tim Specht
Tim Specht

Reputation: 3218

MFMessageViewController and inline UIImage

I'm currently composing an HTML-Mail using MFMailComposer. Everything like Background Color etc. is working quite fine, I can even embed images inline which are located under an online URL. But when I want to embed an locally stored UIImage everything is messed up. Therefore I'm converting the data to base64 and use the image-tag as follows

<img src='data:image/png;base64,%@'>

In the preview on the device everything is shown properly, but on my computer in the mail-app there is only the placeholder question mark image, when I view the source of the mail all there seems to be send is

<img src="cid:(null)">

Also I'm able to successfully log the base64 encoded data on the device, it just simply doesn't make it's way to the server or down from there. Attaching the image is not a solution as I NEED the image to be inline and not at the end of the mail :(

UPDATE:

Here's are the lines I use to embed the image into HTML inline:

[body appendFormat:@"<p><b><img src='data:image/png;base64,%@'/></b></p>",[[NSData dataWithData:UIImagePNGRepresentation([dict objectForKey:@"graphImage"])] base64EncodedString]];

Upvotes: 2

Views: 673

Answers (3)

J&#252;rg Otter
J&#252;rg Otter

Reputation: 77

It is possible. There was a breaking change in iOS: There are no "new lines" allowed in the base64 data.

see this thread: Base64 HTML embedded images not showing when mailed

Upvotes: 0

tarmes
tarmes

Reputation: 15442

It's not possible to embed inline images (I've spend days on the problem).

Oh, how I wish it were....

Upvotes: 1

Allen
Allen

Reputation: 6505

Are you using the following:

NSString *emailBody = [NSString stringWithFormat:@"<img src='data:image/png;base64,%@' alt='testing' />",base64String];
[picker setMessageBody:emailBody isHTML:YES];

Upvotes: 0

Related Questions