1
0

templating.rst 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. .. _templating:
  2. Using Templates
  3. ===============
  4. As templating relies on Jinja, you can set the
  5. template path to a custom folder and
  6. .. code-block:: python
  7. from redmail import EmailSender
  8. email = EmailSender(host="localhost", port=0)
  9. email.set_template_paths(
  10. html="path/html/templates",
  11. text="path/text/templates",
  12. )
  13. .. note::
  14. If you are dissatisfied with default HTML and text
  15. table templates, you can also pass ``html_table``
  16. and ``text_table`` to specify the templates used
  17. to render embedded tables:
  18. .. code-block:: python
  19. email.set_template_paths(
  20. html_table="path/html/tables",
  21. text_table="path/text/tables",
  22. )
  23. Next we will make a simple template, let's call it
  24. ``event_card.html``:
  25. .. code-block:: html
  26. <h1>Hi {{ participant }}!</h1>
  27. <p>
  28. Thank you for being a valuable member of our
  29. community! We are organizing an event
  30. {{ event_name }} and we would like to invite
  31. you.
  32. </p>
  33. <p>Kind regards,<br>
  34. <em>{{ organizer }} </em>
  35. </p>
  36. Then we can use this template:
  37. .. code-block:: python
  38. email.send(
  39. subject='email subject',
  40. receivers=['first.last@example.com'],
  41. html_template='event_card.html',
  42. body_params={
  43. 'participant': 'Jack',
  44. 'event_name': 'Open data',
  45. 'organizer': 'Organization.org'
  46. }
  47. )