Send email from Python over SMTP
Python's smtplib talks SMTP directly. Point it at Unitpost on port 587 with STARTTLS. Django and Flask wrap this; this page is the bare client.
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 with smtplib
Pythonimport os import smtplib from email.message import EmailMessage msg = EmailMessage() msg["From"] = "you@yourdomain.com" msg["To"] = "customer@example.com" msg["Subject"] = "Hello from Python" msg.set_content("Sent via SMTP.") msg.add_alternative("<p>Sent via SMTP.</p>", subtype="html") with smtplib.SMTP("smtp.unitpost.com", 587) as smtp: smtp.starttls() smtp.login("unitpost", os.environ["UNITPOST_API_KEY"]) smtp.send_message(msg)