简体   繁体   English

如何通过python将base64图像嵌入到SendGrid电子邮件中?

[英]How to embed base64 images into SendGrid email via python?

According to this article by Sendgrid, inline embedding (Base64 Encoding) is supported.根据 Sendgrid 的这篇文章,支持内联嵌入(Base64 编码)。

However the below code does not work, because it does not show the actual image, which should look like this .但是下面的代码不起作用,因为它没有显示实际的图像,应该是这样的

import sendgrid

html = """
<div>
    <p>Taken from wikpedia</p>
    <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
    9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
</div>
"""
sg = sendgrid.SendGridClient('api_key')
message = sendgrid.Mail()
message.set_html(html)
message.add_to('test@gmail.com')
message.set_from('test2@gmail.com')
message.set_subject('test subject')
print sg.send(message)

The email I received looks like the following:我收到的电子邮件如下所示: 在此处输入图片说明

Your code might be working , since the alt attribute is being displayed.您的代码可能正在运行,因为正在显示alt属性。

However Gmail (and most other email clients cannot display embedded SVG images in an email.但是 Gmail(和大多数其他电子邮件客户端无法在电子邮件中显示嵌入的 SVG 图像


Not sure how much creative freedom you have, but you could use special characters display a red • :不确定您有多少创作自由,但您可以使用特殊字符显示红色 • :

<p>Taken from wikpedia <span style="color: red;">•</span></p>

or或者

<p>Taken from wikpedia <span style="color: red;">&bull;</span></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM