Master da Web
SMTP guide

Send email with Python over SMTP with smtplib or Django

smtplib ships with Python and Django already has an SMTP backend: all it takes is the host, port 587 with STARTTLS, the username apikey and your sending key. Emails leave signed with your domain, and you see every delivery in the panel.

The sandbox is free for everyone. Already run a cloud service with us? The free plan is yours too.

send.py

import osimport smtplibfrom email.message import EmailMessage msg = EmailMessage()msg["From"] = "My Store <orders@yourdomain.com>"msg["To"] = "ana@example.com"msg["Subject"] = "Order confirmed"msg.set_content("Hi Ana! We received your order.")msg.add_alternative("<p>Hi Ana! We received your order.</p>", subtype="html") with smtplib.SMTP(os.environ["SMTP_HOST"], 587) as smtp:    smtp.starttls()    smtp.login("apikey", os.environ["SMTP_PASSWORD"])    smtp.send_message(msg)

SMTP_HOST and SMTP_PASSWORD are environment variables holding the panel's host and your sending key.

Python

Step by step: SMTP in Python

From a verified domain to the first delivered email, with the result of each send in the panel.

  1. 1

    Verify your domain

    Add the domain in the panel, under Email & SMTP, and publish the DNS records it shows.

  2. 2

    Create a sending key

    The key is the SMTP password. Keep it in an environment variable, out of the code.

  3. 3

    Configure sending

    With smtplib, as in the example; in Django, with the EMAIL_* settings in settings.py.

  4. 4

    Send and follow up

    Run the script, or send_mail in Django, and see in the panel's Activity what happened to the message.

Also useful

settings.py (Django)

Django's SMTP backend, with the same settings: send_mail and Django's own emails go out through it.

settings.py (Django)

import os EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"EMAIL_HOST = os.environ["SMTP_HOST"]EMAIL_PORT = 587EMAIL_USE_TLS = TrueEMAIL_HOST_USER = "apikey"EMAIL_HOST_PASSWORD = os.environ["SMTP_PASSWORD"]DEFAULT_FROM_EMAIL = "My Store <orders@yourdomain.com>"
Beyond SMTP

What you get by sending with Master da Web

Delivery under your domain

DKIM with your domain's key, aligned SPF and DMARC: what Gmail, Yahoo and Microsoft check before they accept.

Per-recipient logs

Delivered, deferred, bounced or marked as spam, with the receiving server's full answer.

Webhooks and suppressions

Signed events in your system, and bounces and complaints taken off the list by themselves.

Free sandbox

A sandbox key captures messages so you can test without delivering anything to anyone.

What it costs

Plans from R$29.00 a month, with 10,000 emails included. If you run a cloud service with us, you start on the free plan, with 3,000 emails a month. The sandbox is free for everyone.

See plans and prices
Discover the SMTP & Email API
FAQ

Questions about SMTP in Python

What comes up most while setting it up.

Set up SMTP in Python today

Create your account, verify your domain and start testing today.