为什么 MFMailComposer 带有 ?邮件中没有显示图像?

发布于 2024-11-19 08:35:23 字数 352 浏览 3 评论 0原文

我正在使用MFMailComposer通过邮件发送一些图像。我将图像转换为 Base64 并使用 标签将图像添加到 HTML 正文(我没有将其添加为附件 )。

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

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

我应该做什么才能让它发挥作用?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゞ记忆︶ㄣ 2024-11-26 08:35:23

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

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

希望这有帮助。

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.

南渊 2024-11-26 08:35:23

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

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

我找到了解决方案...我在苹果雷达上提交了一个关于它的错误。 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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文