Email Channel Setup
Route inbound support emails through the AnswerLoops AI pipeline.
How it works
Email doesn't poll an inbox. AnswerLoops accepts inbound mail through a webhook endpoint: the AI pipeline triages, embeds, and answers each message, then replies directly to the sender via Resend with proper RFC 5322 threading (Message-ID / In-Reply-To / References), so a customer's next reply lands in the same conversation instead of opening a new ticket.
There are two ways to connect:
- Platform-hosted (recommended) — one click, zero setup. AnswerLoops generates a dedicated inbox address on our infrastructure. Share that address, or forward an existing mailbox to it, and signature verification, spam/loop filtering, and delivery-status tracking are all handled for you.
- Bring your own provider (advanced) — point your own SendGrid, Mailgun, Postmark, or Cloudflare account at our webhook with a shared secret. Use this only if you need a custom sending domain the platform-hosted address doesn't give you.
Quickstart: platform-hosted (zero setup)
- Go to Settings → Email.
- Click Connect email. No API key, no DNS record, no webhook config — AnswerLoops immediately generates an address like
[email protected]. - Share that address with customers, or forward your existing support mailbox to it.
- Done. Inbound mail is triaged, answered, and replied to automatically; replies thread correctly on the customer's next reply.
The generated address is set once and is immutable for the life of the integration — reconnecting never changes it.
Advanced: bring your own provider
Use this path only if you need a custom sending domain or already run your own inbound email infrastructure.
1. Prerequisites
RESEND_API_KEYandRESEND_FROMmust be set (used for outbound replies)- An account with a supported email routing provider
2. Configure in AnswerLoops Settings
Under Settings → Email → Advanced: bring your own email provider, enter:
- Reply-from address (optional) — the
From:address for AI replies. Defaults toRESEND_FROMenv var if blank. - Allowed sender addresses/domains (optional) — comma-separated list of emails or domains to accept (e.g.
example.com, [email protected]). Leave blank to accept all inbound email. - Escalation email (optional) — referenced in replies when AI confidence is below threshold.
- Confidence threshold — 0–1, default 0.8.
Click Connect. The webhook secret is shown once — copy it before closing.
3. Configure your email provider
Point your provider's inbound webhook at:
POST https://yourapp.com/api/email/ingestSet the custom secret header:
X-Email-Webhook-Secret: <your webhook secret>Provider-specific guides
SendGrid Inbound Parse
- Settings → Inbound Parse → Add Host & URL
- Enter your domain and
https://yourapp.com/api/email/ingest - Set the
X-Email-Webhook-Secretheader via your SendGrid HTTP POST settings
Mailgun Routes
- Sending → Routes → Create Route
- Match filter:
match_recipient("[email protected]") - Action:
forward("https://yourapp.com/api/email/ingest") - Add
X-Email-Webhook-Secretin the route headers
Postmark Inbound
- Message Streams → Inbound → Settings
- Inbound webhook URL:
https://yourapp.com/api/email/ingest - Set the
X-Email-Webhook-Secretheader in Postmark webhook settings
Cloudflare Email Routing
- Email → Email Routing → Rules
- Forward to a Worker that POSTs to your webhook URL with the secret header
Verify
Send an email to your address. A ticket should appear in /tickets within a few seconds with source badge "Email from [email protected]". Reply to the AI's answer from your own inbox — it should append to the same ticket rather than opening a new one.
Reliability
A few things worth knowing about how the pipeline handles the messy realities of email:
- Idempotent by construction. Every inbound email is keyed on its RFC
Message-ID, so a provider webhook retry is a no-op, never a duplicate ticket. - Mail-loop guarded.
Auto-Submitted,Precedence,X-Auto-Response-Suppress,List-Id, and no-reply sender patterns are all detected and rejected before a reply is ever generated. A per-sender reply throttle backstops anything that slips through. - Spam-tolerant, fail-open. Provider spam signals are honored when present, but their absence never blocks a legitimate email.
- HTML fallback. HTML-only emails are converted to plain text rather than silently dropped.
- Delivery-status visibility. Bounces, spam complaints, and delivery failures on outbound replies are tracked against the ticket and surfaced as a badge on the ticket detail page.
- Rate-limited per org. A compromised or misbehaving upstream account can't burn one org's AI spend or flood the ticket queue for everyone else.
Environment variables
| Variable | What it is |
|---|---|
RESEND_API_KEY | Required for outbound replies |
RESEND_FROM | Default reply-from address (e.g. [email protected]) |
RESEND_WEBHOOK_SECRET | Svix signing secret for Resend's inbound webhook (whsec_...) — required for the platform-hosted path |
EMAIL_INBOUND_DOMAIN | Domain used when generating platform-hosted inbound addresses (defaults to inbox.answerloops.app) |
The BYO-provider webhook secret is generated automatically and stored in the database per org — no env var needed for that path.
Notes
- Quoted reply chains are stripped — only the new message content is ingested.
Subjectis prepended to the body so triage has full context.- Messages under 10 characters are ignored.
- Replies set
Message-ID,In-Reply-To, andReferencesfor correct email-client threading.