How to send email with Python

Use the REST API with requests, or the standard library's smtplib — both send from your verified domain.

1. REST API with requests

import os, requests

r = requests.post(
    "https://api.novamail.nexaclouds.online/emails",
    headers={
        "Authorization": f"Bearer {os.environ['NOVAMAIL_API_KEY']}",
        "Idempotency-Key": "order-1042",
    },
    json={
        "from": "Your Store <hello@mail.yourstore.com>",
        "to": ["customer@example.com"],
        "subject": "Order #1042 confirmed",
        "html": "<p>Thanks for your order!</p>",
    },
    timeout=10,
)
r.raise_for_status()
print(r.json()["id"])

2. smtplib (standard library)

import os, smtplib, ssl
from email.message import EmailMessage

msg = EmailMessage()
msg["From"] = "hello@mail.yourstore.com"
msg["To"] = "customer@example.com"
msg["Subject"] = "Order confirmed"
msg.set_content("Thanks for your order!")

with smtplib.SMTP("postal.novamail.nexaclouds.online", 587) as s:
    s.starttls(context=ssl.create_default_context())
    s.login(os.environ["SMTP_USER"], os.environ["SMTP_PASS"])
    s.send_message(msg)

Django

EMAIL_HOST = "postal.novamail.nexaclouds.online"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ["SMTP_USER"]
EMAIL_HOST_PASSWORD = os.environ["SMTP_PASS"]