Can you and how do you embed images in an email when using the Gmail API?

后端 未结 1 1523
南笙
南笙 2020-12-19 00:34

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

相关标签:
1条回答
  • 2020-12-19 01:11

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

    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.

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

    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".

    0 讨论(0)
提交回复
热议问题