1

我正在尝试发送一封带有图像附件并打开 HTML 的电子邮件。问题是当 HTML 打开时,图像显示为内联而不是附件(我使用 gmail)。

如果我设置 isHTML:NO 那么图像会正确显示为可下载的附件。如何将图像作为带有 h​​tml 消息的附件发送?

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

谢谢~!!

4

2 回答 2

0

您的附加图像的方法是正确的,并且您得到的结果也达到了标准。

无论哪种方式,最终用户(无论他们是否使用 Gmail)都应该获得附件。

例如,Windows Live Mail 应该将其视为附件,而在 Mac OS 中使用 Mail,您会看到内嵌的图像。

于 2011-09-25T06:32:49.943 回答
0

您必须将图像添加为附件。您使用 HTML 看到的呈现的电子邮件无法使用缺少的图像 URL 正确呈现。

这是一个示例:需要注意的是,如果您想包含 PDF 之类的内容,则必须包含图像,否则 mfmailcomposer 将失败……这在苹果错误中。

我找到了解决方案...我在 Apple 雷达上提交了一个关于它的错误。MFMailcomposer 有一个错误,您必须将图像连同额外的附件一起发送,才能使 pdf 之类的奇怪项目正常工作...试试这个并用您的卡替换 pdf:

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];
于 2011-12-29T04:34:52.650 回答