Flask-Mail - 发送从 url 渲染的图像

Flask-Mail - send image rendered from url

我正在尝试将渲染图像发送到电子邮件正文中,不是来自 .jpg 文件,而是来自 url link。

下面的代码发送 url,而不是渲染图像。

@celery.task(queue='email')
def send_async_email(to, subject, sender, image, **kwargs):

    msg = Message(subject=subject,
                  sender=sender,
                  recipients=to)

    image = "https://i.scdn.co/image/26816116d2e836116ccf596a855160be5657d936"
    msg.body = "testing"
    msg.html = "<img src={}</img>".format(image)


    mail.send(msg)

    return {'Status': 'mail sent!'}

如何从 link 发送渲染图像?

将任务指向您拥有的 html 模板:

<img src="{{image}}" height="42" width="42" class="bobby img-circle">

然后将 image(url)作为 kwargs

msg.html = render_template('new_consumer.html',**kwargs)
mail.send(msg)

以上应该有效。