Send email from Python
Send sign-in codes, password resets, receipts and alerts from Python with TrivSend's SDK, or through SMTP from Django with no package at all. Every email is signed for your own domain and logged with its delivery result.
Start free · Python in the docs
Install and send
pip install trivsend
export TRIVSEND_API_KEY=ts_...from trivsend import TrivSend, TrivSendError
client = TrivSend() # reads TRIVSEND_API_KEY
try:
email = client.emails.send(
{
"from": "Acme <noreply@notify.example.com>",
"to": "asha@example.com",
"subject": "Welcome to Acme",
"html": "<p>Your account is ready.</p>",
"text": "Your account is ready.",
},
idempotency_key="welcome-42",
)
print(email["id"])
except TrivSendError as e:
print(e.name, e.message, e.status_code)The SDK has no dependencies and runs on Python 3.9 and later. It uses the API's own field names (reply_to, scheduled_at, expires_at), so the API reference applies as written. It works the same in Flask, FastAPI, Celery tasks and plain scripts.
Django: SMTP in settings.py
Django's built-in SMTP backend works as is. send_mail(), password-reset emails and admin error emails all go through TrivSend:
import os
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.trivsend.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = "trivsend"
EMAIL_HOST_PASSWORD = os.environ["TRIVSEND_API_KEY"]
DEFAULT_FROM_EMAIL = "Acme <noreply@notify.example.com>"
SERVER_EMAIL = DEFAULT_FROM_EMAILTest it from python manage.py shell:
from django.core.mail import send_mail
send_mail("TrivSend test", "It works", None, ["you@example.com"])Use the SDK alongside SMTP when you need what SMTP can't do: templates, expiry for one-time codes, or checking an email before you send it.
Know what happened to each email
TrivSend calls your app when an email bounces, is marked as spam or fails. Verify the signature with the SDK, using the raw body before any JSON parsing:
import os
from trivsend import verify_webhook
# Flask
@app.post("/hooks/trivsend")
def trivsend_hook():
event = verify_webhook(request.get_data(), request.headers, os.environ["TRIVSEND_WEBHOOK_SECRET"])
if event["type"] == "email.bounced":
... # mark the address as bad in your database
return "", 204verify_webhook raises ValueError when the signature doesn't match or the timestamp is more than 5 minutes old (webhooks).
Built for app email
- Idempotency keys, so a retried Celery task never sends twice.
- Priority and expiry: sign-in codes go ahead of bulk mail, and a code that would arrive too late is never sent (OTP email).
- Your own domain with DKIM, SPF and DMARC, set up from the dashboard or added for you at Cloudflare.
- Bounces and complaints handled for you, with an automatic suppression list.
- Test keys and simulator addresses to test sign-up flows in CI without sending real mail (testing).
- Free for 3,000 emails a month; paid plans from ₹999 for 50,000 (pricing).
Also see: SMTP relay · Transactional email · Email API for India