A runnable Flask app with a send-mail form demonstrating both ways to send mail from Flask through MailKite:
- SMTP relay (
/send/smtp) — Flask-Mail configured against MailKite's SMTP relay (smtp.mailkite.dev). No new mail abstraction; Flask-Mail already wrapssmtplib, so this is a config change, not new code. - API mode (
/send/api, inmailkite_api.py) — a direct call to the MailKite Python SDK (POST /v1/send). Use this when you need templates, batch sends, or scheduled sends — things plain SMTP can't express.
Full write-up: docs/integrations/flask.md.
cd starters/flask
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # then fill in real values| Var | Required | Purpose |
|---|---|---|
MAILKITE_API_KEY |
yes | mk_live_... — used as both the SMTP password and the API-mode Bearer token |
MAIL_DEFAULT_SENDER |
yes | From: address; must be on a verified domain |
FLASK_SECRET_KEY |
recommended | signs the flash-message session cookie |
MAIL_SERVER |
no | defaults to smtp.mailkite.dev |
MAIL_PORT |
no | defaults to 587 (STARTTLS); MailKite also accepts 465 (implicit TLS) |
MAIL_USERNAME |
no | defaults to mailkite (MailKite only validates the password) |
export $(grep -v '^#' .env | xargs) # or use python-dotenv / your shell's env loader
flask --app app run --debugOpen http://127.0.0.1:5000, fill in the form, and pick Send via SMTP relay or Send via API (SDK). A flash banner reports success or the specific error (bad auth, unverified domain, etc).
python -m py_compile app.py mailkite_api.py| File | Purpose |
|---|---|
app.py |
Flask app: Flask-Mail config against MailKite's SMTP relay, / (form) and /send/smtp routes |
mailkite_api.py |
API-mode alternative: direct MailKite Python SDK call, used by /send/api |
templates/index.html |
The send-mail form + flash messages |
static/style.css |
Minimal styling for the form |
requirements.txt |
Flask, Flask-Mail, mailkite-dev |
.env.example |
Required/optional env vars |