Working with email templates
To send an email, we first need to generate its content. In this recipe, we'll see how to generate a proper template, in both text-only style and HTML.
Getting ready
We should start by installing the mistune
module, which will compile Markdown documents into HTML. We will also use the jinja2
module to combine HTML with our text:
$ echo "mistune==0.8.4" >> requirements.txt
$ echo "jinja2==2.11.1" >> requirements.txt
$ pip install -r requirements.txt
In this book's GitHub repository, there are a couple of templates we will use—email_template.md
at https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition/blob/master/Chapter09/email_template.md and a template for styling, email_styling.html
, at https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition/blob/master/Chapter09/email_styling.html.
How to do it...
- Import the modules:
>...