Petit Mail
This app provides an easy way to send templated mails.
It implements and handles classic SMTP handlers and google-oauth2 handlers.
Using Jinja2 and premailer it can easily template an email and it's subject.
This lib aims to provide a solid base to build more complex service out of it.
The make_server function will return a prepared instance of FastAPI for later user. It is advised to run this app with uvicorn or gunicorn.
Endpoints
POST /send_mail/<_type: Literal['plain', 'html']>
Cet endpoint permet d'envoyer un mail :
{
"data"?:{},
"template_name"?:"",
"content"?:"mail content",
"subject"?:"mail subject",
"from":"sender adress",
"addresses":[]
}
if _type == 'html' then the mail will be templated with the data contained under the data key.
if _type == 'plain' then the mail won't be templated and the content under the content key will be used
GET /reload
Reloads all the template of the server without restarting the server.
How to write a template
This lib uses the Jinja2 template engine, so you can refer to the Jinja2 documentation for the syntax.
There is however, one diffence, in an effort to be concise the subject and the body of each template are in the same file.
So you have to put the subject of the email between this two balises: '' and ''
The body of the email should then be between this two balises: '<mail_content>' and '</mail_content>'
example :
<subject>
Docker | Backup Failed
</subject>
<mail_content>
<body>
{% from "common/centered_button.html" import centered_button %} {% from "common/card.html" import card %} {% call card("La sauvegarde a échouée") %}
<div style="white-space: pre-wrap">
The backup failed at {{data.operation_date}}, if the problem persists, contact an administrator
</div>
<br /> {{ centered_button("Example Incorporation", "https://example.com") }}
<br> Sysadmins {% endcall %}
</body>
</mail_content>
How to reuse components
In order to make a component reusable, you have to place it into the common directory, and you don't have to use the special and <mail_content> balises.
Configuration
Most of the configuration is held in the conf.yaml file.
There are 2 things to configure, the template_provider and the emails senders:
The infos for the template provider are located under the templates key.
Two providers are provided with the library, an S3 provider and a local provider.
They can be used by using the string values 's3' or 'local'. You can see below an example of settings for both types.
exemple :
templates:
# minio doesn't support the last options
s3:
host: documents.staging.example.com
pass_key: password
access_key: key
bucket_name: mail-templates
local:
folder: templates
exemple :
creds:
example:
type: gmail
email: example@example.com
refresh_token: <>
client_id: <>
client_secret: <>
info:
type: gmail
email: info@example.com
refresh_token: <>
client_id: <>
client_secret: <>
# note that here with smtp support it's not the same keys
info2:
type: smtp
email: info@example.com
password: <>
server: <>
server_port: <>
How to get your tokens ?
- Activate your Gmail API keys in the Gmail console
- Get the
credentials.jsonfrom the Gmail console - use the
make_token.pyscript from thegoogle_token_utilsfolder
Metadata
Release files for petit-mail 0.1.5
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 |
|---|---|---|---|---|
| petit_mail-0.1.5.tar.gz | 14.6 kB | Without provenance | Details for petit_mail-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| petit_mail-0.1.5-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for petit_mail-0.1.5-py2.py3-none-any.whl |
Total release size: 30.2 kB
Release files / petit_mail-0.1.5.tar.gz
| Download URL | petit_mail-0.1.5.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
82cd17433710f8c0897af9fb0c5c3d5138c4ee727312229370085989d065e673
|
|
BLAKE2b-256 checksum How to use checksums |
4d46f9b35c7923267d6501f28b57b4d5aa34332f9c73c0fe3d0066466c54d4d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
|
Release files / petit_mail-0.1.5-py2.py3-none-any.whl
| Download URL | petit_mail-0.1.5-py2.py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d855753f27fc3ddaacd4a36359018dd82315ebe706dfbeac674c736924be3d33
|
|
BLAKE2b-256 checksum How to use checksums |
17afcc9f981900cdf3a54e86346677ce08418e160907380c0eb5688437106c5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
|
Security for petit-mail 0.1.5
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.