Email Integration
AgentPress supports bi-directional email communication, allowing your agents to send emails and automatically respond to incoming emails. This guide covers setting up email integration with Resend.
Prerequisites
- A verified domain in ResendÂ
- Resend API key
- Public URL for webhook endpoint (or ngrok for local development)
Setting Up Resend in AgentPress
Email integration is configured at the organization level through the Integrations settings.
1. Verify Your Domain in Resend
- Go to Resend DomainsÂ
- Click “Add Domain” and enter your domain
- Add the DNS records Resend provides (SPF, DKIM, DMARC)
- Wait for verification (usually a few minutes)
2. Enable Inbound Emails
To receive emails at your domain:
- Go to Resend DomainsÂ
- Click on your verified domain
- Enable “Inbound emails”
- Add the MX records Resend provides to your DNS:
Type: MX
Host: @ (or your subdomain)
Value: inbound-smtp.resend.com
Priority: 103. Configure Resend in AgentPress
- Navigate to Settings > Integrations in the console
- Find the Resend card and click “Configure”
- The dialog will show your Webhook URL - copy this for the next step
- Enter your credentials:
| Field | Description |
|---|---|
| API Key | Your Resend API key (starts with re_) |
| From Email | Default sender email address (must be from a verified domain) |
| From Name | Optional display name for outgoing emails |
| Webhook Secret | Signing secret from Resend (starts with whsec_) |
- Click “Test Connection” to verify your API key works
- Click “Save” to store the credentials
4. Configure Webhooks in Resend
AgentPress uses webhooks to receive notifications about incoming emails and delivery status.
- Go to Resend WebhooksÂ
- Click “Add Webhook”
- Use the Webhook URL shown in the AgentPress Integrations dialog
- Configure the webhook events:
Required Webhook Events
| Event | Description | Required |
|---|---|---|
email.received | Inbound email received | Yes - for receiving emails |
email.bounced | Email failed to deliver | Yes - for handling bad addresses |
email.complained | Recipient marked as spam | Recommended |
email.sent | Email accepted by Resend | Optional |
email.delivered | Email delivered to recipient | Optional |
email.opened | Recipient opened email | Optional |
email.clicked | Recipient clicked a link | Optional |
- After creating the webhook, copy the Signing Secret and add it to your Resend configuration in AgentPress
Local Development with Webhooks
Since webhooks require a public URL, use ngrok for local development:
# Terminal 1: Start your API server
bun dev
# Terminal 2: Create a tunnel to your API port
ngrok http 3001Use the ngrok URL as your webhook endpoint:
https://abc123.ngrok.io/webhooks/resendNote: Remember to update the webhook URL in Resend when deploying to production.
Creating Email Inboxes
Email inboxes are configured at the organization level. Each inbox can have agents assigned to automatically respond to incoming emails.
Via the Console
- Navigate to Settings > Email in the console
- Click “Add Inbox”
- Enter the email address (must be from your verified domain)
- Assign agents to handle incoming emails
Via API
// Create an inbox
POST /orgs/:orgSlug/email/inboxes
{
"emailAddress": "support@yourdomain.com",
"displayName": "Support Team"
}
// Assign an agent to the inbox
POST /orgs/:orgSlug/email/inboxes/:inboxId/agents
{
"agentId": "uuid-of-agent",
"isPrimary": true,
"autoRespond": true
}How Email Threading Works
AgentPress maintains email thread continuity using standard email headers:
- Message-ID: Unique identifier for each email
- In-Reply-To: References the parent email
- References: Full chain of message IDs in the thread
When a user replies to an email from your agent:
- Resend receives the reply and sends a webhook to your webhook URL
- AgentPress finds the existing thread using the
Referencesheader - The message is added to the thread
- The assigned agent is triggered to respond
- Agent uses the
sendEmailtool to send a reply with proper threading headers
Agent Email Tools
Agents have access to these tools for email operations:
sendEmail
Send an email to a recipient:
{
"to": "user@example.com",
"subject": "Follow-up on your inquiry",
"body": "Hello! Here's the information you requested...",
"attachDocumentIds": ["uuid-of-generated-doc"] // Optional
}generateDocument
Generate a PDF document that can be attached to emails:
{
"title": "Assessment Report",
"content": "## Summary\n\nYour assessment results..."
}Returns a documentId that can be used with sendEmail.
Email Flow Examples
Outbound: Agent Sends Email After Chat
1. User chats with agent on website
2. Agent generates a PDF report using generateDocument
3. Agent sends email with attachment using sendEmail
4. User receives email with PDF attachedInbound: User Replies to Email
1. User replies to agent's email
2. Resend webhook notification arrives
3. AgentPress finds existing thread
4. Message added to thread
5. Agent triggered to respond
6. Agent uses sendEmail to reply
7. Email threading preserved in user's inboxTroubleshooting
”Email integration not configured” Error
Ensure Resend is configured in Settings > Integrations:
- Navigate to Integrations page
- Configure the Resend integration with your API key and from email
- Test the connection to verify it works
”Domain is not verified” Error
Ensure your configured From Email uses an email address from a verified domain in Resend.
Webhooks Not Arriving
- Verify the webhook URL matches what’s shown in the AgentPress Integrations dialog
- Check the webhook signing secret is correct in both Resend and AgentPress
- Ensure you’ve selected the required events in Resend
- Check your API logs for webhook verification errors
Inbound Emails Not Working
- Verify MX records are properly configured
- Check that “Inbound emails” is enabled for your domain in Resend
- Ensure an inbox exists for the recipient email address
- Verify an agent is assigned to the inbox with
autoRespond: true - Ensure Resend is configured in Settings > Integrations
Security Considerations
- Credentials are stored securely at the organization level
- Webhook signatures are verified using the Resend SDK and your webhook secret
- Email content is sanitized before storage
- Attachments are downloaded immediately (Resend URLs expire in 1 hour)