DOCS: disable jinja
pablo-angulo opened this issue · 1 comments
I want to send a complex email: css and sh*t. I don't need jinja for this email, but I get errors when sending the email, since the css syntax tricks the jinja parser. Could fix it, double curly braces everywhere, but:
Is there a way to send the html without jinja parsing?
Regards
Traceback (most recent call last):
File "./test_embed_redmail.py", line 136, in <module>
email.send(
File "/usr/local/lib/python3.8/dist-packages/redmail/email/sender.py", line 260, in send
msg = self.get_message(
File "/usr/local/lib/python3.8/dist-packages/redmail/email/sender.py", line 334, in get_message
body.attach(
File "/usr/local/lib/python3.8/dist-packages/redmail/email/body.py", line 113, in attach
html, cids = self.render(
File "/usr/local/lib/python3.8/dist-packages/redmail/email/body.py", line 173, in render
html = super().render(html, tables=tables, jinja_params=jinja_params)
File "/usr/local/lib/python3.8/dist-packages/redmail/email/body.py", line 76, in render
return self.render_body(cont, jinja_params={**tables, **jinja_params})
File "/usr/local/lib/python3.8/dist-packages/redmail/email/body.py", line 51, in render_body
template = Environment().from_string(body)
File "/home/user/.local/lib/python3.8/site-packages/jinja2/environment.py", line 1092, in from_string
return cls.from_code(self, self.compile(source), gs, None)
File "/home/user/.local/lib/python3.8/site-packages/jinja2/environment.py", line 757, in compile
self.handle_exception(source=source_hint)
File "/home/user/.local/lib/python3.8/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<unknown>", line 11, in template
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got ':'
Unfortunately, there is no elegant option. You could set the body to just {{ content }}
and pass the actual content using the jinja_params. Put it as markupsafe.Markup
so Jinja considers the thing safe and does not add any escaping.
I have thought maybe there might be a situation where one would like to disable it but could not come up with such where it is necessary. It sounds like in your case it is. I have plans to do a new release very soon and I actually already solved this already. I'll add a new argument use_jinja
that is true by default but can be set false to prevent Jinja templating. Need to write a bit of docs though.