使用Gmail API时,您可以在电子邮件中嵌入图像吗? [英] Can you and how do you embed images in an email when using the Gmail API?

查看:187
本文介绍了使用Gmail API时,您可以在电子邮件中嵌入图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建邮件并使用Gmail创建草稿或电子邮件时,您可以将图片嵌入正文吗?我希望让图像数据实际嵌入到如何复制和粘贴图像(实际数据,而不是链接)到Gmail电子邮件中将图像放置在内容中。

When creating a message and using it to create a draft or email using the Gmail API, can you have an image embedded in the body? I'm looking to have the image data actually embedded similar to how copying and pasting an image (the actual data, not the link) into a Gmail email will place the image right in the content.

可以这样做,还是需要将图像上传到其他位置,并使用HTML将图像嵌入到电子邮件中?任何关于如何做的指针?

Can it be done like this or do I need to upload the image to some other location and use HTML to embed the image in the email? Any pointers on how to do it?

推荐答案

简而言之,您将以与任何电子邮件相同的方式执行此操作服务。

The short answer is that you would do this the same way you would for any email service.

长的答案是您需要创建一个多部分/相关的消息,其中一部分是电子邮件的HTML内容,另一部分是图像。图像部分包含指定图像的ID的Content-ID标题,HTML图像标记使用格式 src 属性中的ID > cid:ID_HERE 。

The long answer is that you need to create a multipart/related message, where one part is the HTML content of the email and the other part is the image. The image part contains a Content-ID header that specifies an ID for the image, and the HTML image tag references that ID in the src attribute using the format cid:ID_HERE.

在Python中如何构建这样的电子邮件的例子如下: https://stackoverflow.com/a/1633493

An example of how to construct such an email in Python is here: https://stackoverflow.com/a/1633493

PS - 看看电子邮件的最佳方法是看原始信息。您可以通过点击邮件旁边的下拉箭头并选择显示原始,查看Gmail中给定电子邮件的原始邮件。

P.S. - A great way to see how emails are constructed is to look at the raw message. You can look at the raw message for a given email in Gmail by clicking the drop down arrow next to the message and selecting "Show original".

这篇关于使用Gmail API时,您可以在电子邮件中嵌入图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆