Search code examples
flaskflask-mail

Flask-Mail - send image rendered from url


I am trying to send a rendered image, not from an .jpg file, but from an url link, into the email body.

The code below sends the url, not the rendered image.

@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!'}

How do I send the rendered image from a link?


Solution

  • Point the task to a html template where you have:

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

    then pass image (the url) as kwargs

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

    The above should work.