Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask + MailKite starter

A runnable Flask app with a send-mail form demonstrating both ways to send mail from Flask through MailKite:

  1. SMTP relay (/send/smtp) — Flask-Mail configured against MailKite's SMTP relay (smtp.mailkite.dev). No new mail abstraction; Flask-Mail already wraps smtplib, so this is a config change, not new code.
  2. API mode (/send/api, in mailkite_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.

Setup

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

Required env vars

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)

Run it

export $(grep -v '^#' .env | xargs)   # or use python-dotenv / your shell's env loader
flask --app app run --debug

Open 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).

Verify without a browser

python -m py_compile app.py mailkite_api.py

Files

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

About

Runnable Flask starter demonstrating MailKite over SMTP relay or the API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages