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.

Need an API key?

SMTP password is a Unitpost API key with emails:send. Username is always unitpost.

  • 5,000 emails/month
  • 3 API keys
  • 5 sending domains
Get free SMTP key
  1. Send with smtplib

    Python
    import 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)
  2. Framework wrappers

    Using a framework? Django, Flask, FastAPI.

Search docs and guides

Search the docs and product guides.