Take the 2-minute tour ×

I am trying to send an email with an image attachment and HTML turned on. The problem is that when HTML is on, the image appears inline instead of as an attachment (I use gmail).

If I set isHTML:NO then the image properly shows up as a downloadable attachment. How can I send the image as an attachment with an html message?

NSData *imageAttachment = UIImageJPEGRepresentation(myUIImage,1);

MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
[mailView setSubject:@"My Email Subject!"];
[mailView addAttachmentData:imageAttachment mimeType:@"image/jpeg" fileName:@"imageAttachment.jpg"];
[mailView setMessageBody:messageBody isHTML:YES];


share|improve this question
I've used this interface a bit and know of no way to control this behavior. (But the attachment should still be downloadable in any decent mail reader.) –  Hot Licks Sep 25 '11 at 0:40
Hi pws5068, did you figure a solution to this yet? –  platypus May 2 at 0:01
add comment

2 Answers

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];  

// 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];
share|improve this answer
Thank you, very helpful! –  c0d3Junk13 Feb 13 at 22:57
add comment

Your method for attaching the image is correct, and the results you are getting are also up to par.

Either way, the end user (whether they use Gmail or not) should get the attachment.

For instance, Windows Live Mail should see it as an attachment, where as using Mail in Mac OS, you would see the image inline.

share|improve this answer
add comment

Your Answer


