Send email from FastAPI over SMTP
Call Python's SMTP client from a FastAPI route. Same host, username, and API-key password as every other stack.
What are the SMTP settings?
| Host | smtp.unitpost.com |
|---|---|
| Username | unitpost(always this literal value) |
| Password | Your Unitpost API key(must carry emails:send) |
| Port (STARTTLS) | 587(or 2587 if blocked) |
| Port (implicit TLS) | 465(or 2465 if blocked) |
| From address | Any address on a verified domain |
How do I set it up?
Send from a route
Pythonimport os import smtplib from email.message import EmailMessage from fastapi import FastAPI app = FastAPI() @app.post("/send") def send() -> dict[str, bool]: msg = EmailMessage() msg["From"] = "you@yourdomain.com" msg["To"] = "customer@example.com" msg["Subject"] = "Hello from FastAPI" msg.set_content("Sent via SMTP.") with smtplib.SMTP("smtp.unitpost.com", 587) as smtp: smtp.starttls() smtp.login("unitpost", os.environ["UNITPOST_API_KEY"]) smtp.send_message(msg) return {"ok": True}Verify delivery
Confirm in Activity.