如何在 iPhone 的 MFMailComposeViewController 中将图像嵌入 html

发布于 2024-10-03 06:34:07 字数 479 浏览 3 评论 0原文

我试图在 html 表中嵌入一堆小图像,我想使用 MFMailComposeViewController 发送这些图像。经过一番搜索后,我发现几乎每个人都建议使用“NSData+Base64 by Matt Gallagher”类来对照片进行 Base64 编码并将其嵌入到 html 中。虽然它看起来可以在 iPhone 和某些电子邮件服务器上运行,但 Gmail 和 Yahoo 不会显示以这种方式嵌入的图像这里提到了这个问题 也是如此。

我想知道是否有人对此有更好的解决方案。我不想在网上上传照片并将链接放在 html 代码中。我希望将图像附加到电子邮件中,并在 html 文本、表格等中显示为内嵌图像。

I am trying to embed a bunch of small images in an html table which I want to send using MFMailComposeViewController. After doing some search I figured out almost everyone is suggesting "NSData+Base64 by Matt Gallagher" class to encode the photo in Base64encoding and embedding it into html. While it looks to work on iPhone and with some email servers but Gmail and Yahoo do not show the images embedded this way. This problem is mentioned here as well.

I was wondering if anyone has a better solution for this. I don't want to upload photos on the web and put the link in the html code. I would like the image to be attached to the email and show up as an inline image within html text,table,...

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

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

发布评论

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

评论(3

匿名。 2024-10-10 06:34:07

不幸的是,目前无法按照您希望的方式完成此操作。 HTML 电子邮件中的内嵌图像使用单独的 MIME 部分,这些部分通过邮件正文中的 content-id 进行引用。 MFMailComposeViewController 不允许您控制消息的 MIME 结构,并且不允许您添加内联引用的内容部分。

将图像数据作为 base64 嵌入到 标签中可以在某些组合上工作 - 它部分是电子邮件客户端的功能,部分是最终用于呈现它的浏览器的功能,但正如您所注意到的,它是不具有广泛的便携性。

This unfortunately cannot be done currently in the way that you desire. Inline images in HTML email use separate MIME parts that are referenced via a content-id from the body of the message. MFMailComposeViewController doesn't give you control over the MIME structure of the message, and doesn't let you add inline referenced content parts.

Embedding image data into <img> tags as base64 can work on some combinations-- it's partly a function of email client and partly of the browser ultimately used to render it, but as you have noticed, it's not broadly portable.

风向决定发型 2024-10-10 06:34:07

我不确定是否要添加到 HTML,但以下是我如何将图像添加为附件:

UIImage *image = [UIImage imageNamed:@"myImage.png"];
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;

NSData *data = UIImagePNGRepresentation(image);
[composer addAttachmentData:data mimeType:@"image/png" fileName:@"curse"];
[composer setMessageBody:@"" isHTML:NO];
[self presentModalViewController:composer animated:YES];
[composer release];

现在您需要的就是将正文更改为 HTML 以及从 HTML 引用附加图像的方法。

I'm not sure about adding to HTML, but here's how I add images as attachments:

UIImage *image = [UIImage imageNamed:@"myImage.png"];
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;

NSData *data = UIImagePNGRepresentation(image);
[composer addAttachmentData:data mimeType:@"image/png" fileName:@"curse"];
[composer setMessageBody:@"" isHTML:NO];
[self presentModalViewController:composer animated:YES];
[composer release];

Now all you need is to change the body to be HTML and a way to reference the attached image from the HTML.

花桑 2024-10-10 06:34:07

将图像上传到某个托管站点,复制链接并将其放置到

<img src='the link.png' /> html on your email message body.

Upload the image to some hosting site, copy the link and put that to

<img src='the link.png' /> html on your email message body.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文