Skip to content

Webhooks

Webhooks allow MoMail to notify your application in real-time when events occur, such as receiving a new email.

Retrieve all configured webhooks.

GET /webhooks
{
"success": true,
"data": [
{
"id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"secret": "whsec_****",
"active": true,
"createdAt": "2024-01-15T10:30:00.000Z"
}
]
}

Configure a new webhook endpoint.

POST /webhooks
{
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"secret": "your_webhook_secret"
}
FieldTypeRequiredDescription
urlstringYesHTTPS URL to receive webhook payloads
eventsarrayYesList of events to subscribe to
secretstringNoSecret for verifying webhook signatures
EventDescription
email.receivedNew email received
email.processedEmail processing completed
domain.verifiedDomain verification successful
api_key.createdNew API key created
{
"success": true,
"data": {
"id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"secret": "whsec_****",
"active": true,
"createdAt": "2024-01-15T10:30:00.000Z"
}
}

Retrieve details for a specific webhook.

GET /webhooks/{id}
ParameterTypeRequiredDescription
idstringYesWebhook UUID
{
"success": true,
"data": {
"id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received"],
"active": true,
"createdAt": "2024-01-15T10:30:00.000Z",
"lastDelivered": "2024-01-15T14:22:00.000Z",
"deliveryStats": {
"success": 150,
"failure": 2
}
}
}

Modify an existing webhook configuration.

PUT /webhooks/{id}
{
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed", "domain.verified"],
"secret": "new_webhook_secret"
}
{
"success": true,
"data": {
"id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed", "domain.verified"],
"active": true
}
}

Remove a webhook configuration.

DELETE /webhooks/{id}
{
"success": true,
"data": {
"message": "Webhook deleted successfully"
}
}
{
"event": "email.received",
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"email_id": "msg_abc123",
"message_id": "<message-id@sender.com>",
"subject": "Project Update",
"from": "sender@example.com",
"to": ["recipient@yourdomain.com"],
"date": "2024-01-15T10:29:55.000Z",
"mailbox_id": "mb_xyz789",
"domain": "yourdomain.com",
"has_attachments": true,
"thread_id": "thread_123"
}
}

MoMail signs webhook payloads using your webhook secret. Verify the signature to ensure the webhook came from MoMail.

X-Webhook-Signature: sha256={signature}
const crypto = require('crypto');
function verifyWebhook(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload, 'utf8')
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expected)
);
}
// Express.js example
app.post('/webhooks/momail', (req, res) => {
const signature = req.headers['x-webhook-signature'];
const payload = JSON.stringify(req.body);
const secret = process.env.WEBHOOK_SECRET;
if (!verifyWebhook(payload, signature, secret)) {
return res.status(401).send('Invalid signature');
}
// Process webhook
console.log('Received event:', req.body.event);
res.status(200).send('OK');
});

If your endpoint returns a non-2xx status code, MoMail will retry:

AttemptDelay
1Immediate
25 seconds
325 seconds

After 3 failed attempts, the webhook is marked as failing and must be manually reactivated.

Terminal window
# Create webhook
curl -X POST https://api.momail.io/v1/webhooks \
-H "X-API-Key: your_key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received"],
"secret": "whsec_your_secret"
}'
# List webhooks
curl https://api.momail.io/v1/webhooks \
-H "X-API-Key: your_key"
# Delete webhook
curl -X DELETE https://api.momail.io/v1/webhooks/wh_abc123 \
-H "X-API-Key: your_key"