Skip to main content

How to Connect Email to AI Agent

Connect your Flametree AI agent to email systems using IMAP/SMTP protocols to enable automated communication through email channels.


Prerequisites

  • Email Account with IMAP/SMTP access enabled
  • SMTP server credentials for sending emails
  • IMAP server credentials for receiving emails
  • 2-Factor Authentication (2FA) enabled on your email account
  • App password or OAuth credentials (strongly recommended)
  • Admin access to your Flametree account
  • Dedicated email account (recommended) to avoid conflicts and ensure consistent message handling

Setting Up Email Integration

Step 1: Prepare Email Account

  1. Enable IMAP/SMTP Access

    • For Gmail: Enable Less secure app access or use App Passwords
    • For Outlook: Ensure IMAP is enabled in account settings
    • For corporate emails: Contact IT admin for server details
    tip

    For reliable message handling, use a dedicated email account for the agent, for example support@company.com. This helps avoid conflicts with personal or shared business inboxes.

  2. Generate App-Specific Password

    • Gmail: Google Account > Security > 2-Step Verification > App passwords
    • Outlook: Account Security > Additional security options > App passwords
    • Yahoo: Account Security > Generate and manage app passwords

If authentication fails:

  • Verify username and password
  • Ensure 2FA is configured with an app password
  • Check that IMAP/SMTP access is enabled

Step 2: Collect Email Server Information

tip

If you use Gmail, Outlook/Office 365, Yahoo, or Exchange, jump straight to Popular Email Provider Settings for ready-made server addresses and ports.

You can provide a single value or set up multiple accounts. Save these values from your email provider:

ParameterDescriptionExample
UsernameFull email addressuser@example.com
PasswordAccount or app passwordyour_app_password
IMAP ServerIncoming mail serverimap.gmail.com
IMAP PortIMAP server port993 (SSL)
SMTP ServerOutgoing mail serversmtp.gmail.com
SMTP PortSMTP server port587 (TLS) or 465 (SSL)

If connection fails:

  • Verify server URLs and ports
  • Ensure your network allows outbound SMTP/IMAP connections
  • Try alternative SMTP ports (587 or 465)

Configuring Flametree Integration

Step 1: Create Email Integration

  1. Navigate to Channels

    • Go to Settings > Channels
    • Open Email (IMAP/SMTP)
    • Select Add +
  2. Fill Configuration

    tip

    For Gmail, Outlook/Office 365, Yahoo, or Exchange, see Popular Email Provider Settings for ready-made values

    FieldDescriptionRequiredExampleValue Source
    NameCustom integration nameSupport Email ConnectorYour choice
    DescriptionIntegration purposeCustomer support email integrationYour choice
    AddressEmail address used by the channelsupport@company.comYour email account
    PasswordPassword for the email address⚠️ Non-OAuth onlyyour_app_passwordYour email account
    IMAP ServerIncoming mail serverimap.gmail.comEmail provider settings
    IMAP PortIMAP server port. Use 993 for SSL unless your provider requires another port.993Email provider settings
    SMTP ServerOutgoing mail serversmtp.gmail.comEmail provider settings
    SMTP PortSMTP server port. Use 587 for TLS or 465 for SSL unless your provider requires another port.587Email provider settings
    Enable OAuthEnables OAuth authentication for the whole channelfalseYour email account
    OAuth refresh tokenRefresh token for OAuth authentication⚠️ OAuth onlyrefresh_token_hereOAuth provider console
    OAuth token URIToken endpoint URI⚠️ OAuth onlyhttps://oauth2.googleapis.com/tokenOAuth provider docs
    OAuth client IDOAuth client ID⚠️ OAuth onlyclient_id_hereOAuth provider console
    OAuth client secretOAuth client secret⚠️ OAuth onlyclient_secret_hereOAuth provider console
    Inbox check interval [env CHECK_INTERVAL]Interval in seconds for checking the inbox.15Your choice

    Field notes

    • Multiple values: For Address, Password, IMAP Server, IMAP Port, SMTP Server, SMTP Port, and OAuth credential fields, you can enter comma-separated values. Keep the same order across related fields. Example: first@mail.com, second@mail.com.

    • Enable OAuth: OAuth applies to the whole channel. All accounts in one integration must use the same authentication method.

    • Address: When multiple accounts are connected, Flametree sends outbound emails through them in a fixed repeating sequence. After the first email, each recipient stays linked to the same sender account.

    • Inbox check interval [environment variable CHECK_INTERVAL]: Use a value that matches the channel priority:

      • 15 seconds — Critical support channels
      • 60 seconds — Standard business email
      • 300 seconds — Low-priority or bulk email

      More on environmental variables and how to set them

  3. Click Save to create the integration.

  4. Click Start in the upper-right corner to start the channel.

Step 2: Connect to AI Agent

  1. Open Agent Configuration

    • Navigate to your target AI agent's settings
    • Go to Communication channels section
  2. Assign Channel

    • Select your email integration from the list
    • Toggle Inbound ON if this agent should reply to incoming emails; leave it OFF for outbound (send-only) flows. When the same mailbox is connected to multiple agents, only one should have Inbound ON
    • Save the agent configuration
  3. Restart the agent: click Stop agent then Start agent to apply the changes.

important

If emails are not received, verify IMAP configuration and inbox check interval. Also ensure the channel is active.

ProviderSMTP ServerSMTP PortIMAP ServerIMAP PortSecurity
Gmailsmtp.gmail.com587imap.gmail.com993TLS/SSL
Outlook/Office 365smtp.office365.com587outlook.office365.com993TLS/SSL
Yahoosmtp.mail.yahoo.com587imap.mail.yahoo.com993TLS/SSL
Exchangemail.company.com587mail.company.com993TLS/SSL

Configuration Options

Configure additional email settings through Set Environment Variables.

Additional Account-Specific Variables

The values can be single or comma-separated for multiple accounts.

VariableDescriptionDefault
EMAIL_NAMEDisplay name shown in the From field. Comma-separate for multiple accountsNone
IMAP_MAILBOXIMAP folder to read mail from (e.g. INBOX, Support)INBOX
SMTP_ATTEMPTSNumber of retries before giving up on a send5
SMTP_DELAYPause between SMTP retry attempts (seconds)5
FULL_EMAIL_ADDRESSFull sender string Name <address@x.com>. Overrides EMAIL_NAMENone
FROM_TEMPLATEFormat for the From header (placeholders: name, address){} <{}>
MESSAGE_CONTENT_TYPEMIME type of outgoing body (text/plain or text/html)text/plain

Channel-Level Variables

VariableDescriptionDefault
EMAIL_RETRY_LIMITNumber of email client request attempts before graceful exit3
EMAIL_MAX_ATTACHMENT_BYTESMaximum size of inbound attachments (bytes). Set to 0 to disable limiting10485760 (10 MB)

Security Considerations

Credential Security

  • Use app passwords instead of main account passwords
  • Enable 2FA on email accounts
  • Rotate credentials regularly
  • Use environment variables for sensitive configuration
  • Prefer OAuth authentication when available

Email Security

  • TLS/SSL encryption for all connections
  • Validate sender identity before processing

Was this article helpful?