Webhooks
Receive real-time notifications about email events via HTTP callbacks.
Webhooks allow your application to receive real-time notifications when events occur in your SendMailOS account. When an event is triggered, we send an HTTP POST request to your configured endpoint with event details.
Available Events
Email Events
Triggered when an email is successfully sent to the recipient's mail server
Triggered when the email is confirmed delivered to the recipient's inbox
Triggered when the recipient opens the email (requires tracking pixel)
Triggered when the recipient clicks a link in the email
Triggered when an email bounces (hard or soft bounce)
Triggered when a recipient marks the email as spam
Subscriber Events
Triggered when a new subscriber is added to your list
Triggered when subscriber details are modified
Triggered when a subscriber opts out of your emails
Campaign Events
Triggered when a campaign finishes sending to all recipients
Workflow Events
Triggered when a workflow execution begins for a subscriber
Triggered when a workflow execution completes all steps
Payload Format
All webhook payloads follow a consistent JSON structure. Here is an example payload for an email.delivered event:
"id": "evt_1234567890abcdef",
"type": "email.delivered",
"created_at": "2024-01-15T10:30:00Z",
"data": {
"email_id": "em_abc123",
"message_id": "<[email protected]>",
"recipient": "[email protected]",
"campaign_id": "camp_xyz789",
"timestamp": "2024-01-15T10:30:00Z",
"metadata": {
"subscriber_id": "sub_456",
"tags": ["newsletter", "weekly"]
}
}
}
Integration Examples
curl -X POST https://api.sendmailos.com/api/v1/webhooks \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"url": "https://yourapp.com/webhooks/sendmail",
"events": ["email.delivered", "email.bounced", "email.complained"],
"secret": "whsec_your_signing_secret"
}'
Signature Verification
All webhook requests include a signature in the X-Sendmail-Signature header. You should verify this signature to ensure the request came from SendMailOS and was not tampered with.
X-Sendmail-SignatureHMAC-SHA256 signatureX-Sendmail-TimestampUnix timestamp of requestX-Sendmail-EventEvent type (e.g., email.delivered)TIMESTAMP="1705315800"
PAYLOAD='{"id":"evt_123",...}'
SECRET="whsec_your_signing_secret"
SIGNATURE=$(echo -n "${TIMESTAMP}.${PAYLOAD}" | \
openssl dgst -sha256 -hmac "$SECRET" | \
sed 's/^.* //')
echo "Expected signature: $SIGNATURE"
Retry Handling
If your endpoint returns a non-2xx status code or times out (30 seconds), we will retry the webhook delivery using exponential backoff.
Best Practice: Always return a 200 status code as quickly as possible, even if you need to process the webhook asynchronously. This prevents unnecessary retries and ensures reliable delivery.