如何在 iPhone 的 MFMailComposeViewController 中将图像嵌入 html
我试图在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,目前无法按照您希望的方式完成此操作。 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.我不确定是否要添加到 HTML,但以下是我如何将图像添加为附件:
现在您需要的就是将正文更改为 HTML 以及从 HTML 引用附加图像的方法。
I'm not sure about adding to HTML, but here's how I add images as attachments:
Now all you need is to change the body to be HTML and a way to reference the attached image from the HTML.
将图像上传到某个托管站点,复制链接并将其放置到
Upload the image to some hosting site, copy the link and put that to