red-mail
red-mail copied to clipboard
issue with embed base64 image into jinja2 template
Hello Mikael, Thank you for making red-mail, it's great helper.
Describe the bug It seems it's not possible to embed base64 image into jinja2 template. Image is always attached to the email instead being embedded.
To Reproduce
Code:
# picture is passed from python PIL from another function as arg
# picture = base64.b64encode(buff.getvalue())
# this way, I avoid saving and reading picture from disk, so base64 is super useful.
tp_decoded = base64.b64decode(picture)
red_email.send(
subject="The Subject",
receivers=["[email protected]"],
html_template="email/reset.html",
body_images={
"myimage": tp_decoded,
},
)
Template file:
<h1>Hello,</h1>
<p>
{{ myimage }}
</p>
End result is attached image instead of embedded:
Expected behavior Expecting that this would work the same way, as when no template is being used like in this example:
tp_decoded = base64.b64decode(picture)
red_email.send(
subject="The Subject",
receivers=["[email protected]"],
html="""
<h1>Hello,</h1>
<p>Auth code is valid for 30 minutes</p>
{{ myimage }}
""",
body_images={
"myimage": tp_decoded,
},
)
Without template, image is embedded correctly:
Email provider:
- Email service: Gmail, Protonmail
- Application to view the email: Web Gmail, Web Protonmail
Environment (please complete the following information if relevant):
- OS: Linux
- Python version [3.10.5]
- Red Mail version [0.4.0]
Why encode and decode again? You should be able to just embed the bytes
if you can pass around the PIL.Image object instead, you should be able to embed that as well
I may have misunderstood you problem, if these dont work please clarify the original type of the image object that is passed to these lines of code