Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with embed base64 image into jinja2 template #52

Open
hexkey opened this issue Jul 18, 2022 · 1 comment
Open

issue with embed base64 image into jinja2 template #52

hexkey opened this issue Jul 18, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@hexkey
Copy link

hexkey commented Jul 18, 2022

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:

email

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:
email2

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]
@hexkey hexkey added the bug Something isn't working label Jul 18, 2022
@hexkey hexkey changed the title BUG: issue with embed base64 image into jinja2 template Jul 19, 2022
@Waghabond
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants