[
]
template-mailer
A simple python client for sending mass emails from html templates.
Description
The template-mailer lets you fill variables in html-templates and send the populated content via email. It makes use of the jinja2 templating langauge (Reference).
Usage
Provide your html-template as a string to the render_template-method:
>>> from template_mailer import render_template
>>> template = "<html> foo: {{ variable }} </html>"
>>> data = {"variable": "bar"}
>>> render_template(template, data)
'<html> foo: bar </html>'
Use the SMTPClient to send the rendered template as html-email with the SMTPClient:
>>> from template_mailer import SMTPClient
>>> smtp_client = SMTPClient()
>>> smtp_client.send("targetemailalldress@test.test", "subject", "message")
By default the client will look for the following environment variables:
SMTP_HOST,
SMTP_PORT (starttls),
EMAIL_USER (your email address),
EMAIL_PASSWORD
You can provide the SMTP configurations in plain form as well:
>>> smtp_client = SMTPClient("smtp.gmail.com", 587, "your_email@gmail.coim", "your_password")
Options
Encryption
The default email encryption is TLS. An SSL option is not yet provided and will be part of a future release.
Missing data
The render_template method will throw an error if you don't provide enough data to populate all template-variables:
>>> from template_mailer import render_template
>>> template = "<html> foo: {{ variable }} ham: {{ second_variable }} </html>"
>>> data = {"variable": "bar"}
>>> render_template(template, data)
Traceback (most recent call last):
...
jinja2.exceptions.UndefinedError: 'second_variable' is undefined
To change this policy you can provide the option undefined="allow" to the render_template-method:
>>> from template_mailer import render_template
>>> template = "<html> foo: {{ variable }} ham: {{ second_variable }} </html>"
>>> data = {"variable": "bar"}
>>> render_template(template, data, undefined="allow")
'<html> foo: bar ham: </html>'
Logging
By default the SMTPClient uses the root-logger with log-level INFO. You can inject your own logger into the client:
>>> from template_mailer import SMTPClient
>>> import logging
>>> some_logger = logging.getLogger("demo")
>>> smtp_client = SMTPClient(logger=some_logger)
Note
This project has been set up using PyScaffold 3.2.3. For details and usage information on PyScaffold see https://pyscaffold.org/.
Metadata
Release files for template-mailer 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| template-mailer-0.4.0.tar.gz | 14.8 kB | Without provenance | Details for template-mailer-0.4.0.tar.gz |
Release files / template-mailer-0.4.0.tar.gz
| Download URL | template-mailer-0.4.0.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f41ff32c1ef2ce369ea88aa77a8a29e557a709d8552c8bf7c27b44b6505bceec
|
|
BLAKE2b-256 checksum How to use checksums |
d71464e6743493a2ec695d50c02bc85928580efdaf9cafc700a8e2f1fb3f248b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4
|
Security for template-mailer 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.