Installation
Copy
Ask AI
pip install requests
Send an email
Copy
Ask AI
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
Copy
Ask AI
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
Copy
Ask AI
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
Copy
Ask AI
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"])