Send individual and bulk emails right from your applications or in a lightweight microservice.
- Python 3.8
- Docker
Postmaster uses the Jinja template engine to quickly render HTML on-the-fly. It supports the same syntax and features as Flask templates.
For email clients that don't support HTML, Postmaster will also automatically convert your templates into plain text.
For example:
<p><b>Hello, {{ name }}</b></p>
<p>Your order is ready.</p>
<p>Sincerely, Aperture Science</p>
will render in plain text as:
**Hello, {{ name }}**
Your order is ready.
Sincerely, Aperture Science
import postmaster
client = postmaster.Client(
username='noreply@aperturescience.com',
password='emailPassword',
smtp_host='smtp.gmail.com',
default_from='Aperture Science <noreply@aperturescience.com>')
headers = postmaster.Headers(
to_addr=['jane.doe@example.com'],
subject='Your order receipt')
client.send_from_template(
headers=headers,
template='templates/order-receipt.html',
jinja_env={'name': 'Jane'})
client.close()
git clone https://github.com/streamcord/postmaster.git
cd postmaster
docker build -t postmaster:latest .
docker run -d \
-e POSTMASTER_TOKEN=$POSTMASTER_TOKEN \
-v "$(pwd)"/templates:/app/templates:ro \
-h postmaster \
--name postmaster \
postmaster:latest
Then, to send an email:
import requests
POSTMASTER_TOKEN = 'your_token_here'
req = requests.post(
'http://postmaster/emails/@new',
headers={
'Authorization': POSTMASTER_TOKEN
},
data={
'bcc': False,
'env': {
'name': 'John'
},
'from': 'Aperture Science <noreply@aperturescience.com>',
'subject': 'Hello, world!',
'template': 'order-receipt.html',
'to': ['john.doe@example.com']
})
assert req.status_code == 204