Back to Main Site

Connect Email (IMAP / SMTP Cron Sync) and AI Chat to Perfex CRM Unified Inbox with PolyUtilities v3.7.0

Connecting your support and sales mailboxes via IMAP and SMTP brings customer email directly into the Perfex CRM Unified Inbox alongside WhatsApp, Messenger, Slack, SMS, and Viber, with zero public webhooks or third-party email relays required. In PolyUtilities for Perfex CRM v3.7.0 by HeadRandom, the Email channel (Poly_omnichat_email_adapter) hooks cleanly into Perfex Core Cron (after_cron_run) using an atomic store-before-mark-read polling engine so zero customer emails are ever dropped during database hiccups, while outbound replies use Perfex CRM's native SMTP configuration to preserve 100% SPF, DKIM, and DMARC deliverability.

How Atomic Store-Before-Mark-Read IMAP Polling Protects Customer Emails

Traditional email-to-CRM importers often mark an email as \Seen the moment they read its body. If PHP times out or a database error occurs half a second later, that customer inquiry silently vanishes from the unread queue.

PolyUtilities v3.7.0 eliminates dropped email risk inside the OmniChat & AI Hub architecture with a strict four-stage atomic sync pipeline triggered automatically on Perfex's after_cron_run hook:

  1. Zero-Webhook Cron Polling: Every 5 minutes (on standard Perfex Cron), Poly_omnichat_channel_manager::poll_email_channels() iterates through active Email channels and opens {host:993/imap/ssl}INBOX via PHP's native ext-imap, scanning UNSEEN messages by SE_UID (up to 25 emails per Cron cycle to keep memory and execution time lean).
  2. Non-Destructive Peek Read: The adapter fetches email headers and body using FT_UID | FT_PEEK, which intentionally reads the message without setting the \Seen flag on the mail server. Self-sent addresses (from === mailbox) are skipped automatically to prevent bounce loops.
  3. Database Persistence + Audit Log: OmniChat auto-matches the sender email against Perfex Contacts, Clients, and Leads, deduplicates via the RFC Message-ID header, persists the conversation and message in MySQL, and writes a stored audit record to omnichat_email_poll_logs keyed by (channel_id, mailbox_uid).
  4. Mark \Seen ONLY After Commit: Only after ingest_inbound_events() returns a saved message ID does imap_setflag_full(..., '\\Seen', ST_UID) execute. If any exception occurs, the error is logged with status = 'failed' and the email remains unread on your mail server for safe retry on the next 5-minute Cron run.

PolyUtilities OmniChat Unified Inbox Light Mode Showing Email and Omnichannel Threads

Comparison Dimension PolyUtilities v3.7.0 Email IMAP/SMTP Adapter Basic Email Piping / Third-Party Helpdesk
Public Webhook Needed None (0 exposed webhook attack surface) Inbound mail webhook or SaaS forwarding
Dropped Email Prevention Atomic FT_PEEK + omnichat_email_poll_logs store-before-mark-read Marks read on fetch (risk of silent drops)
Batch Cap per Cron Cycle Up to 25 unread messages per mailbox per 5-min run Unbounded spikes can trigger PHP timeouts
Outbound Deliverability Uses Perfex Core SMTP (preserves SPF, DKIM, DMARC) Third-party relay domains often hurt inbox placement
Credential Security AES-256-CBC encrypted vault (enc:v1:...) in MySQL Plaintext configs or external cloud storage
AI Email Assistant Summarize, Draft, Translate, Rewrite, Sentiment, KB Q&A Extra per-agent AI add-on ($20 to $50+/seat)

Prerequisites Before Adding an Email Channel

Confirm these three server prerequisites inside your Perfex CRM environment:

  1. PHP imap Extension Enabled: Verify ext-imap is active in your PHP configuration (php -m | grep imap or cPanel Select PHP Version > Extensions > imap). If imap_open() is missing, the adapter exits gracefully with a notice and zero fatal errors.
  2. Perfex Core Cron Running Every 5 Minutes: Ensure your server crontab invokes Perfex's cron endpoint every 5 minutes (*/5 * * * *), verified under Setup > Settings > Cron Job.
  3. Perfex Core SMTP Configured and Tested: Configure and test outbound email under Setup > Settings > Email (SMTP Host, Port 465 SSL or 587 TLS, Username, Password). Outbound replies sent from the Perfex CRM Unified Inbox dispatch directly through this verified SMTP transport.

Step 1: Prepare Credentials for Gmail, Google Workspace, cPanel, or Outlook

Choose the instructions matching your mail provider:

Option A: Gmail or Google Workspace (App Password Required)

Google blocks standard account passwords over IMAP for security. Follow Google's official Gmail IMAP setup:

  1. Open your Google Account security settings and confirm 2-Step Verification is turned ON.
  2. Visit Google App Passwords, enter an app label such as Perfex OmniChat IMAP, and click Create.
  3. Copy the 16-character App Password (remove the spaces when pasting into Perfex).
  4. Use IMAP Host imap.gmail.com (Port 993, SSL) and configure Perfex Core SMTP with smtp.gmail.com (Port 465 SSL or 587 TLS) using the same App Password.

Option B: Custom cPanel, Plesk, CyberPanel, or Microsoft 365 / Outlook

Mail Provider IMAP Hostname (Enter in Perfex) Default Port & Encryption Password / Auth Requirement
Gmail / Google Workspace imap.gmail.com Port 993 (SSL) 16-char Google App Password (2FA required)
cPanel / Plesk / CyberPanel mail.yourdomain.com Port 993 (SSL) Mailbox email password created in hosting panel
Microsoft 365 / Outlook outlook.office365.com Port 993 (SSL) App Password + IMAP enabled in Exchange Admin
Zoho Mail imap.zoho.com (or imappro.zoho.com) Port 993 (SSL) Zoho App-Specific Password
Fastmail imap.fastmail.com Port 993 (SSL) Fastmail IMAP App Password

Step 2: Configure the Exact 3 Fields in Perfex OmniChat Settings

Complete installation via the PolyUtilities installation and setup guide, ensure External Channels is enabled under PolyUtilities > OmniChat Settings > General, then open the Channels tab and add your mailbox:

Perfex Settings Field Required Value for Email Channel Exact Mapping in Poly_omnichat_email_adapter
Channel Type Email (IMAP / SMTP) (email) Dispatches to Cron IMAP polling & Core SMTP sender
Channel Name Team inbox name (e.g. Billing & Support) Used as the outbound From display name & default Re: subject prefix
Account ID Full Support Email (support@company.com) Stored as imap_username and outbound From email address
Token / API Key / Password 16-char App Password or IMAP Password Stored encrypted (AES-256-CBC) as imap_password
App Secret / Webhook Secret Leave blank Not needed (Email uses zero-webhook Cron polling)
Verify Token / IMAP Host IMAP Hostname (e.g. imap.gmail.com or mail.yourdomain.com) Stored as imap_host (defaults to Port 993, SSL, folder INBOX)

Click Save Channel. Because multi-account Email channels are supported out of the box, you can connect support@company.com, sales@company.com, and billing@company.com simultaneously into the same Unified Inbox. Within 5 minutes (on the next Perfex Cron cycle), unread customer emails begin syncing automatically with last_sync_at updated in the database.

Step 3: Reply Through Perfex SMTP with SPF, DKIM, and DMARC Intact

When an agent replies to an email thread inside Unified Inbox, Poly_omnichat_email_adapter::send_outbound() loads Perfex's configured CodeIgniter email library, sets your channel's From address and display name, converts line breaks cleanly while HTML-escaping body text, attaches any locally vetted files (after passing OmniChat's Attachment Firewall and Image CDR / PDF anti-malware scan), and dispatches via your domain's authorized SMTP server.

Because replies originate from your own authenticated SMTP relay rather than an external shared IP pool, your SPF, DKIM, and DMARC alignment stays 100% intact, maximizing customer inbox placement and avoiding spam folder penalties.

Supercharging Long Email Threads with AI Copilot and 1-Click CRM Conversion

Email threads frequently contain multi-paragraph histories, technical logs, and cross-border inquiries that take agents 5 to 10 minutes each to digest. Pairing your IMAP/SMTP channel with the Multi-Provider AI Chat Hub & Key Rotation Pool cuts handling time by 50%+ at a fraction of a cent per email ($0.15/$0.60 per 1M tokens on gpt-4o-mini or near-$0 using Google Gemini 2.5 Flash free-tier rotation):

  • AI Summarize: Condenses a 15-reply customer email chain into a clear 3-bullet executive brief before you write a word.
  • AI Draft & 3 Smart Suggestions: Generates polished, brand-aligned email drafts using your System Persona and Perfex Knowledge Base articles.
  • AI Rewrite & Grammar Fix: Transforms quick bullet notes into Professional, Friendly, or Concise replies with zero typos.
  • AI Translate & Sentiment: Translates foreign-language customer emails inline and flags angry or urgent billing threads via Automation Rules (Negative Sentiment Alert -> Set Priority: urgent).
  • 1-Click Conversion to Perfex Tickets or Leads: Click Create Ticket to turn a complex technical email into a tracked Perfex Support Ticket pre-filled with the email subject and transcript (where staff also gain the Perfex CRM Ticket AI Copilot & Slash Macros), or click Create Lead to capture inbound sales inquiries straight into your Perfex pipeline.

PolyUtilities Ticket AI Copilot Accelerating Email and Ticket Replies Inside Perfex CRM

Troubleshooting IMAP Polling and SMTP Delivery Issues

  • New Emails Are Not Appearing in Unified Inbox: First verify Perfex Core Cron ran within the last 5 minutes under Setup > Settings > Cron Job. Next confirm PHP ext-imap is installed and check the last_error status on the channel (for Gmail, normal passwords always trigger Authentication failed; switch to a 16-character App Password).
  • Emails Already Marked Read Before Connecting Do Not Sync: By design, Poly_omnichat_email_adapter polls UNSEEN emails so connecting a 5-year-old mailbox does not flood Unified Inbox with thousands of historical threads. Mark a specific test email as Unread to verify ingestion immediately.
  • Outbound Email Replies Report SMTP delivery failed: Test your core SMTP credentials under Setup > Settings > Email > Send Test Email. Ensure your SMTP provider allows sending from the From email address entered in the channel's Account ID field (for Google Workspace, configure "Send mail as" aliases if sending from a group address).

Ready to unify IMAP/SMTP Email with WhatsApp, Messenger, Instagram, Telegram, Slack, SMS, Viber, and Zalo OA inside one CRM workspace? Explore PolyUtilities for Perfex CRM from HeadRandom.

Frequently Asked Questions (FAQ)

Does connecting Email to Perfex OmniChat require configuring a public webhook?

No. Unlike WhatsApp, Slack, or Viber, the Email adapter uses zero-webhook PHP IMAP polling executed automatically during Perfex Core Cron (after_cron_run). This works seamlessly even on internal or firewalled Perfex servers that cannot accept inbound third-party webhooks.

What happens if my MySQL server restarts while OmniChat is polling IMAP emails?

Thanks to the atomic store-before-mark-read design (FT_PEEK + omnichat_email_poll_logs), an email is marked \Seen on the mail server only after it is safely stored in Perfex MySQL. If a database or network error happens mid-run, the email stays unread and retries cleanly on the next 5-minute Cron cycle with zero lost messages.

Why does Gmail reject my regular password when configuring IMAP?

Google disabled legacy less-secure password authentication for IMAP/SMTP. You must enable 2-Step Verification on your Gmail or Google Workspace account, create a 16-character App Password at myaccount.google.com/apppasswords, and paste that App Password into the Perfex Token / API Key / Password field.

Will existing Perfex Contacts and Leads link automatically when they email my support inbox?

Yes. Poly_omnichat_channel_model::resolve_or_auto_map_crm_identity() automatically matches incoming sender email addresses against Perfex Contacts (linking both the Contact and parent Client) and Leads, surfacing open tickets, invoices, and projects right inside Unified Inbox.

How does PolyUtilities prevent bounce or auto-reply email loops?

Two built-in checks protect your mailbox: Poly_omnichat_email_adapter ignores any incoming email whose sender address matches the connected mailbox address (from === user), and Poly_omnichat_channel_manager enforces a configurable per-conversation AI auto-reply cooldown (default 10s) plus Message-ID deduplication.

PolyUtilities boosts Perfex CRM with powerful customization and workflow enhancements. Create multi-level menus, group menus by purpose, embed iframe links, open content in popups, and reorganize system navigation with drag-and-drop. Add dynamic widgets across dozens of display positions, use right-click navigation, manage custom JS/CSS, support multi-company and multi-address structures, and convert selected text into tasks instantly. Combined with banners, announcements, quick-access shortcuts, and many smart utilities, PolyUtilities turns Perfex CRM into a faster, cleaner, and highly personalized workspace for every team member.

HeadRandom Perfex CRM Engineering

Need a Custom Perfex CRM Module, Bug Fix, or CodeIgniter 4 Upgrade?

Avoid broken updates, PHP 8.2-8.4 errors, and risky core edits. HeadRandom provides custom Perfex CRM module development, upgrade, and bug-fixing services for any third-party or custom module on your Perfex CRM installation, plus upgrading Perfex CRM from CodeIgniter 3 to CodeIgniter 4 via IgniteCore for Perfex CRM.

Build, Upgrade & Fix Any Perfex CRM Module

Develop new custom modules from scratch, patch bugs or hook conflicts on existing client modules, and update legacy code for clean PHP 8.2-8.4 compatibility with zero core file hacks. View Perfex CRM module development scope.

CodeIgniter 3 to CodeIgniter 4 via IgniteCore

Migrate your Perfex CRM runtime to CodeIgniter 4 (4.7.6) using IgniteCore for Perfex CRM (independent module by HeadRandom) with Dual-Mode CI3 fallback, 32% to 75% lower latency, 50% less RAM, and custom CI4 porting for third-party modules. See CI3 to CI4 upgrade options.

40+ Commercial Modules Published100% Zero Core File Edits0 High Security Audit GateTransparent Pricing from $39

Combine 2+ HeadRandom services (Custom Module, IgniteCore CI4 Upgrade, or Website Care) to save 30% automatically.