Quick setup examples
Flask
Send your first email from a Flask route by calling the MailBlastr API with requests.
Python has an official package — pip install mailblastr — and it works unchanged from a Flask view. The example below instead POSTs JSON to https://www.mailblastr.com/api/emails with the `requests` library, keeping the dependency list short. See SDKs for the package.
Prerequisites
- A MailBlastr API key.
- A verified domain to send from.
1. Install an HTTP client
Pip
pip install requests2. Set your API key
.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx3. Send email from a route
POST the email body to the MailBlastr API from a route handler. The easiest way to send is with the html field.
index.py
import os
import requests
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def index():
res = requests.post(
"https://www.mailblastr.com/api/emails",
headers={"Authorization": f"Bearer {os.environ['MAILBLASTR_API_KEY']}"},
json={
"from": "Acme <onboarding@yourdomain.com>",
"to": ["delivered@mailblastr.dev"],
"subject": "hello world",
"html": "<strong>it works!</strong>",
},
)
res.raise_for_status()
return jsonify(res.json())
if __name__ == "__main__":
app.run()A successful call returns the created email's
id. See every supported field in the Send an email reference.