Skip to main content

Installation

pip install requests

Send an email

import requests

response = requests.post(
    "https://app.usesendi.com/api/emails",
    headers={
        "Authorization": "Bearer snd_your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "from": "you@yourdomain.com",
        "to": ["user@example.com"],
        "subject": "Hello from Sendi",
        "html": "<p>It just works.</p>"
    }
)

data = response.json()
print(data["id"])

With name in from

response = requests.post(
    "https://app.usesendi.com/api/emails",
    headers={
        "Authorization": "Bearer snd_your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "from": "Your App <noreply@yourdomain.com>",
        "to": ["user@example.com"],
        "subject": "Welcome",
        "html": "<h1>Welcome aboard</h1>",
        "tags": {"campaign": "welcome"}
    }
)

Batch send

response = requests.post(
    "https://app.usesendi.com/api/emails/batch",
    headers={
        "Authorization": "Bearer snd_your_api_key",
        "Content-Type": "application/json"
    },
    json=[
        {"from": "you@yourdomain.com", "to": ["user1@example.com"], "subject": "Hi", "text": "Hello"},
        {"from": "you@yourdomain.com", "to": ["user2@example.com"], "subject": "Hi", "text": "Hello"}
    ]
)

Error handling

response = requests.post(
    "https://app.usesendi.com/api/emails",
    headers={"Authorization": "Bearer snd_your_api_key", "Content-Type": "application/json"},
    json={"from": "you@yourdomain.com", "to": ["user@example.com"], "subject": "Test", "text": "Hello"}
)

if response.ok:
    print("Sent:", response.json()["id"])
else:
    print("Error:", response.json()["error"])