在 iOS 中撰写新电子邮件时获取附加图像的 Content-ID
我在 iOS 中使用 MFMailComposeViewController 来创建新的动态电子邮件,但在尝试使用内联图像时遇到了问题。
我首先尝试将图像添加为 base64 编码字符串,即
<img src="data:image/png;base64, blahblahblah" />
但我只能在 iPad 上查看它,而 Outlook/Entourage 会忽略它,即使我可以在源代码中看到它!
所以现在我尝试将图像添加为附件并链接到它通过它的内容ID,即
<img src="cid:BF6E8B41-4D74-419E-B55E-8F18A07381AE" id="BF6E8B41-4D74-419E-B55E-8F18A07381AE" width="509" height="220">
但不知道如何通过获取cid
代码!
当我使用 AddAttachmentData
附加图像时,图像会转到底部并实际生成带有 cid 的 标记!
此外,这个 ID 似乎会随着每封新电子邮件而改变。上面的是我的第一次尝试,然后我发送了另一个,内容 ID 更改为
<img src="cid:59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" id="59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" width="509" height="220">
我必须这样做的原因是因为这是动态生成的图像,它需要位于电子邮件模板内。
编辑
我开始认为这是不可能的。我已经研究了好几个小时了,看起来 iOS 不允许你附加图像并通过其 CID 链接到它。谢谢苹果 -_-
I'm using the MFMailComposeViewController
in iOS to create a new dynamic email but have run into an issue when trying to use inline images.
I first tried adding the image as a base64 encoded string, i.e.
<img src="data:image/png;base64, blahblahblah" />
But I can only view that on the iPad while Outlook/Entourage ignore it even though I can see it in the source!
So now I'm trying to add the image as an attachment and link to it via it's content ID, i.e.
<img src="cid:BF6E8B41-4D74-419E-B55E-8F18A07381AE" id="BF6E8B41-4D74-419E-B55E-8F18A07381AE" width="509" height="220">
But have no clue how to get the cid
through code!
When I attach an image using AddAttachmentData
, the image goes to the bottom and actually generates an <img />
tag with the cid!
Additionally, this ID seems to change with every new email. The one above was my first try, then I sent another one and the Content-ID changed to
<img src="cid:59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" id="59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" width="509" height="220">
The reason I have to do this is because this is a dynamically generated image and it needs to sit inside an email template.
EDIT
I'm beginning to think that this isn't possible. I've been researching for hours now and it looks like iOS won't let you attach an image and link to it via its CID. Thanks Apple -_-
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到了 MFMailComposeViewController 的相同限制。它没有办法获取电子邮件附件的内容 ID (cid),因此无法编写通过
img src='cid:...'
引用附件的 html 电子邮件。由于大多数电子邮件客户端都会忽略数据 URL(内联 Base 64 编码图像),因此使用 iOS 应用程序中的图像撰写 html 电子邮件的最佳选择是将图像托管在 Web 上并将其引用为img src='http ://...'
。大多数电子邮件客户端会询问用户下载图像的权限,因此这并不理想,但它显然是 iOS 中使用公共 API 的唯一选项。I've hit the same limitation of
MFMailComposeViewController
. It exposes no way to get content id (cid) of an email attachment, so there is no way to compose an html email message that references the attachment viaimg src='cid:...'
. Since most email clients ignore data urls (inline base 64 encoded images), the best option for composing an html email message with images from an iOS app is to host the images on the web and reference them asimg src='http://...'
. Most email clients will ask the user for permission to download the images, so this is not ideal, but it's apparently the only option in iOS using public APIs.