Skip to content
Back to Documentation

Email Integration

Connect a support mailbox over IMAP/SMTP and let your agent answer customer emails.

Connect a mailbox

Go to Dashboard → Channels → Email responder. There are two ways to connect a mailbox:

  • Sign in with Google or Microsoft (one click, no passwords) when your AgentPro administrator has enabled it. See the next section.
  • IMAP/SMTP for any other provider: Yahoo, Zoho, Fastmail, cPanel and self-hosted servers, and Gmail with an App Password.

Owners and admins can connect or change a mailbox; agents can read threads and reply. With IMAP/SMTP the channel reads new mail over IMAP and sends replies over SMTP. You need:

  • The mailbox address (for example support@yourcompany.com) and an optional display name.
  • IMAP host and port (usually 993 with SSL/TLS) and the login.
  • SMTP host and port (usually 587 with STARTTLS, or 465 with SSL/TLS) and the login.
  • An agent. Replies are generated from the agent's knowledge and persona, so the channel cannot be created without one. Train the agent first.

Use Test connection before saving: it logs in to both servers and reports the exact IMAP and SMTP result. Saving also verifies both connections, then starts the sync. From that moment the channel only processes mail that arrives after it was connected. Existing mail in the inbox is never read or auto-replied.

TLS certificates are verified. For self-hosted servers with a self-signed certificate, tick Allow self-signed certificates. Mail is left unread in the mailbox unless you enable Mark emails as read after processing.

Both setup paths and Test connection report problems in plain language with the fix next to them ("wrong password: create an App Password", "port 587 needs SSL/TLS unticked", "host name not found"). A first-time setup that fails leaves nothing behind; the form keeps what you typed so you can correct it.

Outlook.com / Microsoft 365: Microsoft no longer accepts passwords for IMAP/SMTP on most tenants, so these mailboxes need Sign in with Microsoft. If that button is not shown, ask your AgentPro administrator to enable it, or ask your Microsoft 365 admin to allow IMAP basic auth and Authenticated SMTP for the mailbox. The inbound webhook is a third option.

Sign in with Google / Microsoft

When the buttons are available, pick the agent that should answer emails, click Sign in with Google or Sign in with Microsoft, and approve the mailbox. AgentPro then:

  • reads the mailbox address from the account and fills in the Google or Microsoft mail servers for you;
  • verifies IMAP and SMTP with the account's tokens (XOAUTH2) before saving anything;
  • stores the tokens encrypted and renews them automatically. No App Password, no expiry to track.

If the sign-in is ever revoked (password change on the account, admin removes the app), the channel shows Needs attention with a Sign in again button and the owners are notified. Google Workspace or Microsoft 365 administrators may have to allow the AgentPro app for their organisation first.

The buttons appear only when the AgentPro installation has Google / Microsoft OAuth apps configured (GOOGLE_OAUTH_CLIENT_ID, MICROSOFT_OAUTH_CLIENT_ID and their secrets). Self-hosted installations register those apps once in Google Cloud Console / Microsoft Entra with the redirect URL {API_URL}/api/v1/webhooks/email/oauth/{google|microsoft}/callback.

App passwords

Providers with two-factor authentication do not accept your normal password for IMAP/SMTP. Create an app password instead:

Gmail / Google Workspace

  1. Enable 2-Step Verification under Google Account → Security.
  2. Open Security → 2-Step Verification → App passwords and create one (name it "AgentPro").
  3. Use the 16-character code as both the IMAP and the SMTP password.
  4. Make sure IMAP is enabled: Gmail → Settings → See all settings → Forwarding and POP/IMAP.
  5. Hosts: imap.gmail.com:993 (SSL/TLS) and smtp.gmail.com:587 (STARTTLS).

Yahoo

Account Security → Generate app password. Hosts: imap.mail.yahoo.com:993 and smtp.mail.yahoo.com:587.

Zoho, Fastmail, iCloud

All three require app-specific passwords: Zoho Mail → My Account → Security → App Passwords (imap.zoho.com:993 / smtp.zoho.com:587); Fastmail → Settings → Privacy & Security → Third-party apps (imap.fastmail.com:993 / smtp.fastmail.com:587); iCloud → appleid.apple.com → App-Specific Passwords (imap.mail.me.com:993 / smtp.mail.me.com:587).

Passwords are encrypted at rest and never returned by the API. When editing a connection, leave the password fields empty to keep the stored values.

What gets auto-replied

Every new inbound email is stored on a thread and mirrored into the unified inbox. The AI only replies when all of these hold:

  • The channel has an agent linked.
  • The email arrived after the mailbox was connected.
  • It is not automated mail (see loop protection below).
  • AI is still enabled on the conversation. A human reply from the inbox or the thread view pauses the AI for that conversation.
  • The thread is not resolved or marked as spam.
  • Nobody replied on the thread between the email arriving and the delay ending, and no newer email superseded it.

The response delay gives your team time to answer first. Replies are scheduled as background jobs, so they survive a restart and are re-checked right before sending. To avoid runaway conversations the AI answers at most one email per thread every 10 minutes and three emails per sender per day; further mail is stored for a human.

New mail is detected instantly on servers that support IMAP IDLE and otherwise on the Check for new mail every N seconds interval (default 60 s, 15 s minimum) from the auto-reply settings.

Before the message reaches the AI, quoted text ("On … wrote:", lines starting with >, forwarded header blocks) and signatures are stripped so only the new text is answered. The previous emails on the thread (last 10) are provided as context. The answer is sent as a proper reply (Re: subject, In-Reply-To/References headers), to the Reply-To address when present, with everyone else on the original email in CC, and your signature appended.

Why did the AI not reply?

Every stored email that was not answered has a reason. Check these in order:

  • No agent linked: the channel page shows a red notice; pick an agent in the auto-reply settings.
  • Automated mail: out-of-office replies, bounces, newsletters and no-reply senders are never answered (see loop protection).
  • AI paused on the conversation: a human replied from the inbox or thread, which hands the conversation to people. Resume AI from the inbox.
  • Thread resolved or marked as spam: reopen it, or the customer's next email reopens it automatically.
  • Someone answered first: a human or a newer email on the thread superseded it during the response delay.
  • Draft waiting for review: auto-send is off, or the quality score was below 50%. Open Threads → Needs review.
  • Rate cap: one AI reply per thread per 10 minutes and three per sender per day.
  • Sending failed: the status card shows Last send error with the reason (SMTP password rejected, provider blocked sending, daily quota). Fix it and approve the draft from the thread.
  • Mail arrived before the connection: only mail received after the mailbox was connected is processed.

Loop protection

Automatic replies to automatic mail create infinite loops. These messages are stored but never answered:

  • Auto-Submitted header other than no, Precedence: bulk/list/junk/auto_reply, X-Autoreply, X-Autorespond, X-Auto-Response-Suppress.
  • Mailing list mail (List-Id, List-Unsubscribe).
  • Senders such as no-reply@, noreply@, mailer-daemon@, postmaster@, bounce@, notifications@, and mail from the connected address itself.
  • Delivery reports (multipart/report) and subjects starting with "Automatic reply", "Out of office", "Undeliverable", "Delivery status".

Every AI reply is sent with Auto-Submitted: auto-replied, X-Auto-Response-Suppress: All and Precedence: auto_reply, so other auto-responders stay quiet too.

Draft / review mode

Turn off Send AI replies automatically to review every answer. The AI still writes a reply, but saves it as a draft on the thread and marks the thread Needs review. Open Channels → Email → Threads to approve and send it, edit it first, or write your own reply.

Even with auto-reply on, answers with a low quality score (below 50%) are saved as drafts instead of being sent. A manual reply discards pending drafts.

Threads and the inbox

Emails are grouped into threads by In-Reply-To and References headers, falling back to the same sender and subject within 7 days. Each thread is linked to a conversation in the unified inbox, so your team can read and answer email next to chat and WhatsApp. Inbound mail appears as a visitor message, AI replies as agent messages and manual replies as teammate messages.

Marking a thread resolved resolves the conversation; a new email from the customer reopens both. Attachments up to 10 MB each (25 MB per message) are stored and can be downloaded from the thread view by members of your organisation only; executable files are never stored.

Replies are sent from the mailbox address, or from the Send replies from alias if you set one (your provider must allow that login to send as the alias). An optional Reply-To address can redirect customer answers. Because mail leaves through your own provider, your existing SPF, DKIM and DMARC records apply; there is nothing to configure for deliverability.

Status and errors

The connection status card tells you, at a glance:

  • Health badge: Connected, Setup incomplete, Needs attention (the connection stopped and owners were notified) or Paused.
  • Sync: Connected (push via IMAP IDLE plus polling), Reconnecting, Stopped, or Paused after repeated login failures.
  • Last check and the next scheduled check, plus replies sent and mail received in the last 24 hours.
  • Separate error rows for connection, processing and sending, each with a timestamp, so a clean mail check never hides a failed reply.

If the mailbox password is rejected three times in a row, AgentPro stops retrying (providers lock mailboxes after repeated failed logins), marks the channel Needs attention, and emails the organisation owners. Saving the connection again, or a passing Test connection, resumes the sync. Sending failures caused by credentials or the server do the same; one-off failures (a rejected recipient) stay on the thread.

Send me a test email sends a real message to your own address through the mailbox, which catches Send-As and quota problems that a login test cannot.

Inbound webhook (alternative to IMAP)

If your mail provider or forwarding service can POST JSON, you can deliver mail without IMAP. The URL and the signing secret are shown under Advanced: inbound webhook on the channel page, where you can also regenerate the secret. Requests are authenticated with an HMAC-SHA256 of the raw request body using that secret, sent as hex in the X-AgentPro-Signature header. Unsigned or mis-signed requests are rejected, and the same body is accepted only once per 24 hours. Send the optional X-AgentPro-Timestamp header (Unix seconds, within five minutes) and sign "<timestamp>.<raw body>" for replay protection.

POST /api/v1/webhooks/email/<channelId>/inbound
Content-Type: application/json
X-AgentPro-Signature: <hex HMAC-SHA256(webhookSecret, raw body)>
X-AgentPro-Timestamp: 1760400000   (optional; when sent, sign "<timestamp>.<raw body>")

{
  "from": "Jane Doe <jane@example.com>",
  "to": ["support@yourcompany.com"],
  "cc": [],
  "subject": "Order #1234 not delivered",
  "text": "Hi, my order has not arrived yet...",
  "html": "<p>Hi, my order has not arrived yet...</p>",
  "messageId": "<abc123@example.com>",
  "inReplyTo": null,
  "references": [],
  "headers": { "auto-submitted": "no" }
}

from and text or html are required. to, cc, references accept arrays or comma-separated strings. Include the original headers when you can so loop protection works. The webhook feeds the same pipeline as IMAP (threading, inbox mirror, auto-reply rules). Replies are still sent through the channel's SMTP settings.

const crypto = require('crypto');
const body = JSON.stringify(payload);
const signature = crypto
  .createHmac('sha256', process.env.AGENTPRO_WEBHOOK_SECRET)
  .update(body)
  .digest('hex');

await fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-AgentPro-Signature': signature,
  },
  body,
});

Delivery events for outgoing replies can be posted to the events endpoint. Bounces are recorded on the email.

POST /api/v1/webhooks/email/<channelId>/events
X-AgentPro-Signature: <hex HMAC-SHA256(webhookSecret, raw body)>

[
  { "event": "bounce", "messageId": "<reply-id@yourcompany.com>", "reason": "550 mailbox unavailable" },
  { "event": "delivered", "messageId": "<reply-id@yourcompany.com>" }
]

Troubleshooting

  • "IMAP connection failed: Invalid credentials" – use an app password, check that IMAP is enabled for the account, and confirm the username is the full email address.
  • "self signed certificate" – the server's certificate is not trusted. Fix the certificate or enable Allow self-signed certificates for internal servers.
  • "No agent linked" shown as the last sync error – emails are stored but not answered. Pick an agent in the auto-reply settings.
  • Replies are not sent – the status card shows a Last send error row with the SMTP reason; credential problems also flip the channel to Needs attention. Otherwise check the thread: the email may have been flagged as automated, rate limited, saved as a draft, or AI may be paused on the conversation after a human reply (see "Why did the AI not reply?").
  • "Needs attention" after a password change – update the password (or sign in again for Google / Microsoft mailboxes) and the sync resumes automatically.
  • Sync shows "Reconnecting" – the IMAP connection dropped; it reconnects automatically with backoff and polls on the configured interval in the meantime.