Skip to Content
AgentPress is finally here! 🎉
DocsEmail Integration

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

  1. Go to Resend Domains 
  2. Click “Add Domain” and enter your domain
  3. Add the DNS records Resend provides (SPF, DKIM, DMARC)
  4. Wait for verification (usually a few minutes)

2. Enable Inbound Emails

To receive emails at your domain:

  1. Go to Resend Domains 
  2. Click on your verified domain
  3. Enable “Inbound emails”
  4. Add the MX records Resend provides to your DNS:
Type: MX Host: @ (or your subdomain) Value: inbound-smtp.resend.com Priority: 10

3. Configure Resend in AgentPress

  1. Navigate to Settings > Integrations in the console
  2. Find the Resend card and click “Configure”
  3. The dialog will show your Webhook URL - copy this for the next step
  4. Enter your credentials:
FieldDescription
API KeyYour Resend API key (starts with re_)
From EmailDefault sender email address (must be from a verified domain)
From NameOptional display name for outgoing emails
Webhook SecretSigning secret from Resend (starts with whsec_)
  1. Click “Test Connection” to verify your API key works
  2. Click “Save” to store the credentials

4. Configure Webhooks in Resend

AgentPress uses webhooks to receive notifications about incoming emails and delivery status.

  1. Go to Resend Webhooks 
  2. Click “Add Webhook”
  3. Use the Webhook URL shown in the AgentPress Integrations dialog
  4. Configure the webhook events:

Required Webhook Events

EventDescriptionRequired
email.receivedInbound email receivedYes - for receiving emails
email.bouncedEmail failed to deliverYes - for handling bad addresses
email.complainedRecipient marked as spamRecommended
email.sentEmail accepted by ResendOptional
email.deliveredEmail delivered to recipientOptional
email.openedRecipient opened emailOptional
email.clickedRecipient clicked a linkOptional
  1. 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 3001

Use the ngrok URL as your webhook endpoint:

https://abc123.ngrok.io/webhooks/resend

Note: 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

  1. Navigate to Settings > Email in the console
  2. Click “Add Inbox”
  3. Enter the email address (must be from your verified domain)
  4. 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:

  1. Message-ID: Unique identifier for each email
  2. In-Reply-To: References the parent email
  3. References: Full chain of message IDs in the thread

When a user replies to an email from your agent:

  1. Resend receives the reply and sends a webhook to your webhook URL
  2. AgentPress finds the existing thread using the References header
  3. The message is added to the thread
  4. The assigned agent is triggered to respond
  5. Agent uses the sendEmail tool 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 attached

Inbound: 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 inbox

Troubleshooting

”Email integration not configured” Error

Ensure Resend is configured in Settings > Integrations:

  1. Navigate to Integrations page
  2. Configure the Resend integration with your API key and from email
  3. 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

  1. Verify the webhook URL matches what’s shown in the AgentPress Integrations dialog
  2. Check the webhook signing secret is correct in both Resend and AgentPress
  3. Ensure you’ve selected the required events in Resend
  4. Check your API logs for webhook verification errors

Inbound Emails Not Working

  1. Verify MX records are properly configured
  2. Check that “Inbound emails” is enabled for your domain in Resend
  3. Ensure an inbox exists for the recipient email address
  4. Verify an agent is assigned to the inbox with autoRespond: true
  5. 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)
Last updated on