pythonhtmlflaskflask-mail

Flask-mail image not showing when sending html template


I'm very new with flask-email and now i try to send the html email which is have the image inside the body of template but when open this html on email the image does not showing up, so how can i fix it.

This is my example code.

    msg = Message('Test', sender='sender_email',  recipients=['receiver_email'])

    msg.html=render_template('Email.html')
    mail.send(msg)
    return render_template('Email.html')

And this is my img tag in Email.html

<img src="{{ url_for('static', filename='images/logo.png', _external=True) }}">
                

Solution

  • Is the website live? If it isn't it will show link to a localhost image but only you can open it on your network. That is why you can't see it in email client. As soon as you publish your website to a server or domain the link will be public and you will see the image.