When building webhook receivers, it’s critical to verify that incoming requests actually originate from AgentMail and haven’t been tampered with. AgentMail uses Svix to deliver webhooks, which provides cryptographic signature verification.
Without verification, anyone who discovers your webhook URL could send fake requests to your endpoint, potentially causing:
Always verify webhook signatures in production environments.
Each webhook endpoint has a unique signing secret that you’ll use to verify requests. You can find this secret in the AgentMail console when you create your webhook or by fetching your webhook details:
Store your signing secret securely in environment variables. Never commit it to version control or expose it in client-side code.
Every webhook request from AgentMail includes three headers used for verification:
The easiest way to verify webhooks is using the official Svix library, which handles all the cryptographic details for you.
Signature verification requires the exact request body. If you’re using body-parsing middleware (like express.json()), make sure to capture the raw body before parsing, or use express.raw() for your webhook endpoint.
Copy one of the blocks below into Cursor or Claude for webhook verification in one shot.
During development, you’ll need a way for AgentMail to reach your local server. ngrok creates a public URL that tunnels to your local machine.
Create a webhook server file:
You should see output like:
In a new terminal window, start ngrok to create a public tunnel to your local server:
ngrok will display a forwarding URL:
Copy the https:// forwarding URL (e.g., https://da550b82a183.ngrok.app).
/webhooks path: https://da550b82a183.ngrok.app/webhooks.env file:Send an email to one of your AgentMail inboxes, or use the console to send a test event. You should see the webhook received in your terminal:
ngrok is great for local development, but for production you’ll need to deploy your webhook server to a hosting provider. See the next section for deployment options.
For production, you’ll need to deploy your webhook server to a hosting provider that gives you a stable, public HTTPS URL. We recommend Render for its simplicity and generous free tier.
While you might skip verification during local development, always enable it in production environments. A compromised webhook endpoint can be a serious security vulnerability.
Never hardcode your signing secret. Use environment variables or a secrets manager:
If headers are missing, ensure your server/framework isn’t stripping them. Some reverse proxies may need configuration to pass through custom headers.
If you’re using body-parsing middleware, make sure to access the raw body for verification. In Express, use express.raw() for your webhook route.