Why MFMailComposer with <img> is not showing the image in mail?
Asked Answered
Z

2

8

I am sending some images in mail using MFMailComposer. I am converting the image to Base64 and using <img> tag to add images to the HTML body(I am not adding it as attachment).

[htmlString appendFormat:
@"<img src='data:image/png;base64,%@' width=300 height=200 />", imageAsBase64];

The images are displaying correctly in MFMailComposer, but there are no images displayed in the actual mail which is sent from the MFMailComposer.

What should I do to make it work?

Zima answered 7/7, 2011 at 7:19 Comment(2)
What are you using to view the email?Ivan
@Deepmist, Yeah. Sorry for the late reply. I am using Safari in my iMacZima
S
5

I had same problem before couple of weeks and I came to know that Gmail is not supporting embedded images. You can see images in email in other mail provider like your domain email but not in Gmail.

Try to send another email and you can see images. You need to add images as attachment then you can see images and it will display bottom of your email body.

Hope this help.

Stipulate answered 7/7, 2011 at 7:37 Comment(3)
Wow! Great. It shows the image in my Yahoo mail. Thank you! And, there is no other workaround to make the image show in Gmail? Is Gmail the only exception or there are other mail servers that don't display images in this case?Zima
I am not much sure about others but with Gmail it was not working and I have checked in my own mail server and it was working. So I guess except Gmail it should work in all.Stipulate
My Pleasure. If this helps you than you can mark it as answer :)Stipulate
B
0

You have to add the images as an attachment. The rendered email that you see with HTML doesn't get rendered properly with the missing image URL.

here is an example: the caveat is that if you want to include things like a PDF you must include an image otherwise mfmailcomposer will fail... this in an apple bug.

I found the solution... Isubmitted a bug on Apple radar about it. MFMailcomposer has a bug in which you have to send an image along with your extra attachments in order to get the weird items like a pdf to work... try this and replace the pdf with your card:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
NSString *emailSubject = [NSString localizedStringWithFormat:@"MedicalProfile"];
[controller setSubject:emailSubject];


NSString *fileName = [NSString stringWithFormat:@"%@.pdf", profileName];
NSString *saveDirectory = NSTemporaryDirectory();
NSString *saveFileName = fileName;
NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];  

*** YOU MUST INCLUDE AN IMAGE OR THE PDF ATTATCHMENT WILL FAIL!!!***
// Attach a PDF file to the email 
NSData *pdfData = [NSData dataWithContentsOfFile:documentPath];    
[controller addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fileName];


// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"miniDoc" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"doctor"];


[controller setMessageBody:[NSString stringWithFormat:@"%@'s Medical Profile attatched!", profileName] isHTML:NO];

[self presentModalViewController:controller animated:YES];
controller.mailComposeDelegate = self;
[controller release];
Balch answered 29/12, 2011 at 4:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.