Get started
Python quickstart
Send email from Python, Django or Flask with the requests library.
NeedsAny accountTest keys work as soon as you sign up. Nothing is delivered.
A Python SDK is planned. Until then the API is small enough to call directly with requests or httpx.
Send an email
pip install requests
export PADIMAIL_API_KEY=pm_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxximport os
import uuid
import requests
API = "https://api.padimail.app/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['PADIMAIL_API_KEY']}"}
response = requests.post(
f"{API}/emails",
headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())},
json={
"from": "Acme Store <onboarding@sandbox.padimail.app>",
"to": "delivered@test.padimail.app",
"subject": "Hello from PadiMail",
"html": "<p>It works.</p>",
},
timeout=30,
)
if response.ok:
print("Sent", response.json()["id"])
else:
error = response.json()["error"]
print(error["code"], error["message"], error["request_id"])Keep the Idempotency-Key the same if you retry the request, so a retry can't send the email twice.
In Django
Use the SMTP relay to keep Django's send_mail, or call the API from a view:
import os
import requests
from django.http import JsonResponse
def send_receipt(request, order_id):
r = requests.post(
"https://api.padimail.app/v1/emails",
headers={"Authorization": f"Bearer {os.environ['PADIMAIL_API_KEY']}", "Idempotency-Key": f"receipt-{order_id}"},
json={"from": "Acme Store <hello@acme.ng>", "to": request.user.email, "subject": f"Your receipt #{order_id}", "html": "<p>Thanks for your order.</p>"},
timeout=30,
)
r.raise_for_status()
return JsonResponse(r.json())Retries
Retry 429, 500 and 503 responses after a pause, honouring the Retry-After header when it's there. Don't retry other 4xx errors unchanged: they won't succeed.
The same in Node and cURL
const { id } = await pm.emails.send({ from: "Acme Store <onboarding@sandbox.padimail.app>", to: "delivered@test.padimail.app", subject: "Hello", html: "<p>It works.</p>" });curl -X POST https://api.padimail.app/v1/emails -H "Authorization: Bearer $PADIMAIL_API_KEY" -H "Content-Type: application/json" \
-d '{"from": "Acme Store <onboarding@sandbox.padimail.app>", "to": "delivered@test.padimail.app", "subject": "Hello", "html": "<p>It works.</p>"}'Was this page helpful?