【问题标题】:Why MFMailComposer with <img> is not showing the image in mail?为什么带有 <img> 的 MFMailComposer 没有在邮件中显示图像?
【发布时间】:2011-07-07 07:19:38
【问题描述】:

我正在使用 MFMailComposer 在邮件中发送一些图像。我将图像转换为 Base64 并使用&lt;img&gt; 标记将图像添加到 HTML 正文(我没有将其添加为 附件)。

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

图像在 MFMailComposer 中正确显示,但从 MFMailComposer 发送的实际邮件中没有显示图像。

我应该怎么做才能让它工作?

【问题讨论】:

  • 你用什么来查看邮件?
  • @Deepmist,是的。这么晚才回复很抱歉。我在 iMac 中使用 Safari

标签: iphone objective-c ios ios4 mfmailcomposer


【解决方案1】:

几周前我遇到了同样的问题,我知道 Gmail 不支持嵌入图像。您可以在其他邮件提供商(例如您的域电子邮件)中查看电子邮件中的图像,但在 Gmail 中看不到。

尝试发送另一封电子邮件,您可以看到图像。您需要将图像添加为附件,然后您才能看到图像,它将显示在您的电子邮件正文的底部。

希望对您有所帮助。

【讨论】:

  • 哇!伟大的。它显示了我的雅虎邮件中的图像。谢谢!而且,没有其他解决方法可以让图片在 Gmail 中显示吗? Gmail 是唯一的例外,还是有其他邮件服务器在这种情况下不显示图片?
  • 我不太确定其他人,但使用 Gmail 时它无法正常工作,我已签入自己的邮件服务器并且它正在工作。所以我想除了Gmail之外它应该都可以工作。
  • 我的荣幸。如果这对您有帮助,您可以将其标记为答案:)
【解决方案2】:

您必须将图像添加为附件。您使用 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];

【讨论】:

    猜你喜欢
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 2022-12-04
    • 2015-11-13
    • 2013-03-25
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多