开发者

MFMailComposer -- Attach Image with HTML ON

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 att开发者_如何学JAVAachment (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];

Thanks~!!


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜