Email API: Complete Guide for Developers (2026)

Complete Developer Guide

The developer reference for Email API integration

Email is the backbone of developer communication infrastructure. Whether you are building a CRM, a helpdesk, an AI email assistant, or a sales automation tool, you will eventually need to interact with email programmatically. This guide covers everything developers need to know about Email APIs in 2026: how they work, how they compare to SMTP and IMAP, how to authenticate with OAuth 2.0, how to sync inboxes, and how to send messages, with real code examples.

What you will learn

Sync APIs vs sending APIs
OAuth 2.0 multi-provider
Initial and incremental sync
Webhooks and rate limits
Code samples Node and Python
Pick the right architecture
Unipile Email API
GET/api/v1/emails
200
POST/api/v1/emails
200
GET/api/v1/accounts
200
3 providers Gmail logo Outlook logo IMAP logo

Email API Fundamentals

Before diving into providers and integration steps, let's clarify what an Email API actually is, why developers use one instead of raw protocols, and how the two main categories of Email APIs differ. The choice you make at this stage shapes your entire email integration strategy.

What is an Email API?

An Email API (Application Programming Interface) lets applications send, receive, and manage email messages through code. Instead of using traditional protocols like SMTP, IMAP, or POP3, it provides a modern RESTful layer to interact with email data using JSON.

It abstracts away complex server configurations, giving developers unified access to multiple email providers. With a single API call, you can fetch the latest emails from a Gmail inbox, send an attachment via Outlook, or label a message in an IMAP mailbox, without ever touching the underlying protocol stack.

How Email APIs Work

An Email API acts as a bridge between your application and email service providers. It uses secure OAuth 2.0 authentication to grant your app access to a user's inbox and messages, then exposes mailbox operations (list, send, reply, sync, label, archive) through a normalized REST or GraphQL interface.

A typical workflow looks like this:

  • User authorization: the user grants your app permission to access their inbox via an OAuth consent screen.
  • Token storage: your backend receives an access token and refresh token, stored securely server-side.
  • API calls: your app makes authenticated requests to the Email API to read, send, or sync messages.
  • Real-time events: webhooks push notifications to your endpoint whenever a new email arrives or an existing message changes.

Sender APIs vs Sync APIs: Two Different Markets

Before integrating an Email API, it's important to clarify that the term "Email API" covers two distinct markets with very different intentions. Picking the wrong category will cost you weeks of wasted integration work.

Category 1
Transactional & Marketing APIs

APIs that send emails from your own domain. They handle deliverability, queues, and reputation but never access a user's personal inbox.

Major providers
Brevo SendGrid Mailgun Postmark Resend
Use cases Marketing campaigns, password resets, transactional notifications, receipts, newsletters.

Why this distinction matters: if your goal is marketing automation or transactional messaging, solutions like Brevo or SendGrid are great fits. But if you want to integrate personal or professional inboxes for use cases like sales outreach, recruiting, or support, you need an On-Behalf Email API. This guide focuses entirely on the latter category: APIs that connect to Gmail, Outlook, and IMAP to send and receive emails directly from your users' real accounts.

What is an Email Sync API?

An Email Sync API is a set of protocols and tools that allow applications to access, manage, and synchronize email data from various email service providers. These APIs facilitate real-time updates, ensuring that emails are consistent and up-to-date across different devices and platforms. Key features include real-time synchronization, efficient data retrieval, and comprehensive email management capabilities. In practice, an Email Sync API is the technical backbone of every On-Behalf Email API: it's how Gmail, Outlook, and IMAP integrations stay live and accurate inside your product.

Email API vs SMTP/IMAP Direct Integration

Many developers wonder: "why use an Email API at all when SMTP and IMAP are free, open standards?" The answer comes down to development time, reliability, and maintenance cost. Here's a side-by-side comparison.

Aspect
SMTP / IMAP direct
Modern Email API
Protocol
Raw RFC 3501 (IMAP) / RFC 5321 (SMTP) over TCP sockets
REST/JSON over HTTPS, normalized for all providers
Authentication
User passwords or app passwords stored server-side
OAuth 2.0 with refresh tokens, no password handling
Real-time updates
IMAP IDLE polling, fragile, needs persistent connections
Webhooks push events instantly, no polling needed
Provider coverage
One implementation per provider, dozens of edge cases
Single integration covers Gmail, Outlook, IMAP at once
Time to production
2-6 months including OAuth verification reviews
1-7 days from sign-up to first synced inbox

Direct SMTP/IMAP integration is still valid for very narrow use cases (a simple internal cron sending plain-text alerts), but for any product that touches user inboxes at scale, a modern Email API is the only reasonable path.

The Email API Provider Landscape

Three providers cover roughly 95% of professional email worldwide: Gmail (and Google Workspace), Microsoft Outlook / Microsoft 365, and the universal IMAP / SMTP protocols for everything else. Understanding what each one offers, and how they differ, is the first decision you need to make before integrating an Email API into your product.

Gmail logoGmail API

The Gmail API allows developers to access and manage Gmail mailboxes securely using OAuth 2.0 authentication. It is the only sanctioned way to integrate consumer Gmail and Google Workspace accounts at scale: it exposes mailbox listing, message retrieval, label management, drafts, threads, push notifications, and history-based incremental sync via REST endpoints over HTTPS.

Behind the scenes, the Gmail API uses your Google Cloud project's OAuth credentials to act on behalf of a user. Once a user grants consent, you receive an access token (1 hour lifespan) and a refresh token to generate new ones. The hard part is not the API itself: it's passing Google's OAuth verification review, which is mandatory before you can request sensitive scopes like gmail.modify or gmail.send. Reviews take 2-8 weeks and require a CASA Tier 2 or 3 security assessment.

GET /gmail/v1/users/me/messages/MSG_ID 200 OK
{
  "id": "18c1234abcd5678ef",
  "threadId": "18c1234abcd5678ef",
  "labelIds": ["INBOX", "IMPORTANT", "CATEGORY_PERSONAL"],
  "snippet": "Hi team, here is the contract draft you asked for...",
  "historyId": "547821",
  "internalDate": "1714058400000",
  "payload": {
    "mimeType": "multipart/alternative",
    "headers": [
      { "name": "From", "value": "sarah@acme.com" },
      { "name": "To", "value": "michel@unipile.com" },
      { "name": "Subject", "value": "Contract draft v3" }
    ]
  }
}
OAuth Configuration Steps (via Unipile)
  1. Create a Google Cloud project in your Google Developer Console.
  2. Generate an OAuth Client ID (Application type: Web application).
  3. Add Unipile's redirect URI to your authorized origins.
  4. Submit the app for verification with the requested Gmail scopes, or skip this step entirely by using Unipile's pre-verified CASA Tier 2 OAuth app.

Outlook logoMicrosoft Graph API (Outlook)

The Microsoft Graph API provides access to Outlook mailboxes across Microsoft 365, Outlook.com, and Exchange Online. It is the standard approach for connecting business email accounts secured under Azure Active Directory. Unlike Gmail, Microsoft Graph treats email as one resource among many: the same API surface also exposes Calendar, OneDrive, Teams, and Contacts, which is convenient when your product needs more than just inbox access.

The OAuth flow uses Microsoft Entra ID (formerly Azure AD). You register a multi-tenant app, request the appropriate scopes (Mail.Read, Mail.Send, offline_access), and exchange authorization codes for access and refresh tokens. Important caveat: Azure client secrets expire after 12 or 24 months. A lapsed secret silently breaks all token refresh calls in production. Set a calendar reminder, and rotate before expiry.

GET /v1.0/me/messages?$top=1 200 OK
{
  "value": [
    {
      "id": "AAMkAGI2THBMM...",
      "conversationId": "AAQkAGI2THBMM...",
      "subject": "Q1 Pipeline Review",
      "bodyPreview": "Sharing the deck and the metrics dashboard...",
      "isRead": false,
      "importance": "normal",
      "receivedDateTime": "2026-04-07T08:42:11Z",
      "from": {
        "emailAddress": {
          "name": "David Chen",
          "address": "david.chen@acme.com"
        }
      }
    }
  ]
}

IMAP logoIMAP & SMTP (Universal Protocols)

For mail servers that do not provide a native REST API, IMAP remains the universal protocol for mailbox access. This covers everything outside the Google and Microsoft ecosystems: Yahoo Mail, Fastmail, ProtonMail (via Bridge), iCloud Mail, Zoho, GMX, custom corporate mail servers running Postfix or Dovecot, and any provider that respects the IMAP4rev1 standard (RFC 3501). On the sending side, SMTP (RFC 5321) is the matching protocol for outbound messages.

The trade-off with IMAP is integration complexity. Where Gmail and Microsoft Graph give you JSON over HTTPS, IMAP forces you to maintain persistent TCP sockets, parse RFC 822 message bodies, decode quoted-printable and base64 attachments by hand, manage IDLE notifications, and reconnect after every transient network glitch. Most product teams underestimate IMAP by 3x. Unipile abstracts all of that into the same REST endpoints used for Gmail and Outlook.

POST /api/v1/accounts (IMAP connection) 201 Created
// Connect an IMAP/SMTP mailbox via Unipile
{
  "provider": "IMAP",
  "username": "michel@fastmail.com",
  "password": "app-password-here",
  "imap_host": "imap.fastmail.com",
  "imap_port": 993,
  "imap_encryption": "SSL",
  "smtp_host": "smtp.fastmail.com",
  "smtp_port": 465,
  "smtp_encryption": "SSL"
}

// Response
{
  "id": "acc_imap_8f3a7b2c",
  "status": "OK",
  "capabilities": ["IDLE", "CONDSTORE", "MOVE", "UIDPLUS"]
}

Unified Email APIs: One Integration for All Three

Managing three different APIs (Gmail REST, Microsoft Graph, IMAP/SMTP) in a single product quickly becomes painful. Each provider comes with its own authentication model, endpoint shapes, rate limits, error codes, and quirks. A bug fix in your Gmail integration does not propagate to Outlook. A new feature requested by a customer needs to be implemented three times. Your "email integration" team grows from one engineer to four.

A Unified Email API abstracts all that complexity into one standardized REST API, so your developers focus on building product features rather than managing email infrastructure. You write your integration once, and it works across Gmail, Outlook, and IMAP simultaneously.

One REST API for all inboxes

Access, send, and sync messages across Gmail, Outlook, and IMAP through identical endpoints. No per-provider branching in your code.

Centralized OAuth handling

Securely connect Google and Microsoft accounts through Unipile's pre-verified OAuth applications. Skip the entire verification review process.

Real-time email sync

Initial sync, incremental delta sync, and webhook notifications managed automatically. No more polling, no more missed messages.

Enterprise-grade security

SOC 2 Type II certified, GDPR compliant, CASA Tier 2 audited. Tokens and credentials encrypted at rest and in transit.

For a complete step-by-step implementation guide, see our unified email API integration guide.

Email API Integration: From OAuth to Real-Time Sync

A real-world Email API integration follows four phases regardless of which provider you target. Read this section as a checklist before starting your implementation: skipping any step here is the most common reason integrations work in dev and break in production.

OAuth 2.0 Authentication

Both Gmail and Microsoft Graph use the standard OAuth 2.0 authorization code flow. The mechanics are identical: redirect the user to the provider, receive a one-time code on your callback URL, exchange it for a long-lived refresh token server-side, then use that refresh token to mint short-lived access tokens for every subsequent API call.

  • Redirect the user to the provider's authorization endpoint with your client_id, redirect_uri, and the requested scope.
  • The user grants permissions, the provider redirects to your callback URL with a one-time code parameter.
  • Your server exchanges that code for an access_token (1 hour lifespan) and a refresh_token via a back-channel POST.
  • Store the refresh_token securely server-side, encrypted at rest. This is the long-lived credential you use to generate new access tokens automatically.

Security note: never store an access_token in browser local storage or expose it to client-side JavaScript. The refresh_token must live server-side only, encrypted with a key that is itself rotated. A leaked refresh token means full mailbox access until the user manually revokes consent.

Send & Receive Emails

Once authenticated, the next two operations cover 80% of typical Email API usage: fetching the inbox and sending a message. With Unipile's unified API, both work identically across Gmail, Outlook, and IMAP through a single set of endpoints.

# Fetch the latest 50 emails from a connected inbox
curl --request GET \
  --url 'https://api.unipile.com/api/v1/emails?limit=50&folder=inbox' \
  --header 'X-API-KEY: YOUR_API_KEY'

# Send a plain text email
curl --request POST \
  --url 'https://api.unipile.com/api/v1/emails' \
  --header 'X-API-KEY: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "account_id": "YOUR_ACCOUNT_ID",
    "subject": "Hello from Unipile",
    "body": "Hello, this is a plain text email",
    "to": [{"display_name":"John Doe","identifier":"john@example.com"}]
  }'

Unipile also supports the typical advanced send features developers expect: attachments (multipart form-data with multiple files), custom headers (passing arrays of X- prefixed headers), reply-in-thread (using the original message's provider_id), display name override, allowed sender aliases, and open / link tracking with real-time webhook events. Each of these maps to a single field in the request body, no protocol negotiation required.

# Send with attachments + custom headers + tracking
curl --request POST \
  --url 'https://api.unipile.com/api/v1/emails' \
  --header 'X-API-KEY: YOUR_API_KEY' \
  --form 'account_id=YOUR_ACCOUNT_ID' \
  --form 'subject=Contract draft' \
  --form 'body=Please find the v3 attached.' \
  --form 'to=[{"identifier":"sarah@acme.com"}]' \
  --form 'attachments=@/path/to/contract.pdf' \
  --form 'attachments=@/path/to/appendix.png' \
  --form 'custom_headers=[{"name":"X-Campaign-ID","value":"q1-outreach"}]' \
  --form 'tracking_options={"opens":true,"links":true,"label":"q1-outreach"}'

Real-Time Email Sync

Inbox synchronization is the most complex part of any email integration, and the most often misunderstood. A robust email sync implementation has three distinct phases: initial sync, incremental sync, and real-time webhook notifications. Skipping any of them produces an integration that works on day one and breaks at scale.

01

Initial Sync

Download the full mailbox state for the first time. Paginate aggressively, throttle to provider rate limits, and store message IDs in a queue for batch body retrieval.

02

Incremental Sync

Retrieve only messages that changed since the last cycle. Gmail uses historyId, Microsoft Graph uses $deltaToken. Both reduce bandwidth by 95% versus full re-fetches.

03

Real-Time Webhooks

Eliminate polling entirely. Gmail Pub/Sub and Graph subscriptions push events to your endpoint within seconds of any inbox change.

Plan for renewals from day one: Gmail Pub/Sub watch subscriptions expire after 7 days and must be renewed. Microsoft Graph subscriptions on mail resources expire after a maximum of about 3 days. Build subscription renewal into your background job infrastructure before going to production, otherwise your integration will silently stop receiving events.

With a unified email sync API like Unipile, all three phases are handled by the API layer. Your application registers a single webhook endpoint and receives normalized email.received events regardless of whether the underlying mailbox is Gmail, Outlook, or an IMAP server, with no per-provider subscription management required.

Webhooks & Events

Webhooks are how a modern Email API tells your backend something happened, in real time, without you having to ask. Instead of polling /messages every 30 seconds (expensive and slow), you subscribe once, and the provider pushes a JSON payload to your endpoint every time a new email arrives, gets read, gets replied to, or gets deleted.

New email arrives
Unipile normalizes
Webhook fires
Your backend

The events you typically subscribe to are mail_received (a new message landed in the inbox), mail_sent (an outgoing message was successfully delivered), mail_opened (the recipient opened it, if tracking is enabled), mail_link_clicked (the recipient clicked a tracked link), and account_status (the connected mailbox needs reauthentication, e.g. after a password change). Each event carries enough context for your downstream systems to react without making additional API calls.

Built for Developers

Email API Integration for Modern Apps

Connect Gmail, Outlook, and IMAP through a single API. One integration, three providers, zero protocol headaches.

email-sync.js
// Connect any email provider in seconds
import { UnipileClient } from 'unipile-node-sdk';

const client = new UnipileClient({
  dsn: 'https://api.unipile.com',
  token: process.env.UNIPILE_TOKEN
});

// Fetch all emails from linked accounts
const emails = await client.email.list({ limit: 50, folder: 'inbox' });

// Send an email
await client.email.send({
  to: 'contact@example.com',
  subject: 'Hello from Unipile',
  body: 'Your message here...'
});
3 Providers
Gmail
Outlook
IMAP
One Unified API

IMAP Simplified

Abstract away raw IMAP protocol complexity. Full inbox access without implementing RFC 3501.

SOC 2 Certified

Enterprise-grade security with full compliance. Your users data stays protected.

Google Verified

CASA Tier 2 Certified

Use our Google-verified OAuth app for your POC before completing your own certification.

Real-time Webhooks

Instant notifications for new emails, status changes, and events. No polling required.

Sandbox Environment

Test your integration risk-free. Debug with detailed logs and error tracking.

TypeScript Ready

Official Node.js SDK with full TypeScript types. Autocomplete-friendly developer experience.

CRM & ATS Use Cases Powered by the Email API

An Email API is rarely the end goal. It is the foundation under products that need to read, write, and react to emails happening inside their users' real inboxes. Two product categories drive most of Unipile's Email API traffic: CRMs (sales and account management) and ATS platforms (recruiting and hiring). Here is what each unlocks.

Sales Pipeline (auto-synced from inbox)
Live sync
Cold
42
Acme Corp · Discovery
3d ago
Vortex SaaS · Cold reply
5d ago
Engaged
18
Northwind · Demo booked
today HOT
Globex · Pricing Q
1h ago
Negotiation
7
Initech · Contract v3
2h ago
Won
12
Stark Co · Signed
yesterday $48k
Use case 1
CRM · Sales & Account Management

Auto-log every customer email into the right deal record without your reps copy-pasting anything. Trigger pipeline automations the moment a prospect replies. Surface inbox context inside the CRM UI without forcing your users to leave their email client.

  • Auto-logging: match incoming and outgoing emails to the right contact and opportunity automatically.
  • Reply detection: webhook fires within seconds of a prospect's reply, triggering follow-up sequences or owner notifications.
  • Thread sync: reconstitute full conversation threads (subject + thread ID) inside the CRM, including attachments.
  • Send from CRM: compose and send messages from the user's actual mailbox so they appear in the recipient's "From" field as expected.
  • Open and click tracking: attribute engagement back to the deal and forecast closing probability.
Use case 2
ATS · Recruiting & Hiring Velocity

Sync candidate communication into the ATS without manual data entry. Recruiters live in their inbox, your product needs the data to live in the ATS. The Email API bridges that gap in real time, with full conversation history and attachment support.

  • Candidate threads: capture every email exchanged with a candidate inside their profile timeline automatically.
  • Resume parsing: attachments arriving by email are saved to the candidate record and parsed into structured data.
  • Hiring pipeline events: reply from a candidate automatically advances them to the next stage of the hiring funnel.
  • Multi-recruiter coordination: shared visibility on candidate conversations across the recruiting team.
  • Interview scheduling: combine Email API with Calendar API for end-to-end booking flows.

Beyond CRMs and ATS platforms, the same Email API powers AI email assistants (Read, Shortwave, Superhuman-style products), customer support helpdesks (Front, Missive, Help Scout-style), sales engagement tools (Outreach, Salesloft-style), and productivity copilots. The common pattern: any product where the user's mailbox is the source of truth and your job is to make working with it faster.

Google OAuth

Google OAuth, Simplified

Google OAuth verification is complex: consent screens, security reviews, CASA assessments, annual re-certifications. Unipile handles all of it, including the security compliance, so you can focus on building.

DIY Google OAuth
Complex
Create Google Developer Console Project
Set up project, enable Gmail API, configure OAuth credentials
Configure OAuth Consent Screen
App info, logo, privacy policy, terms, authorized domains
Manage OAuth Scopes and Permissions
gmail.send, gmail.labels, gmail.readonly, gmail.modify...
Build Token Refresh and Session Logic
Handle token expiration, refresh cycles, reconnection flows
Record Demonstration Video
Unlisted YouTube video showing OAuth flow and all features
Submit for Google Verification
2-8 weeks review, multiple remediation rounds possible
2-8 weeks wait
CASA Security Assessment (Tier 2 or 3)
External audit by third-party assessor, mandatory for restricted scopes
~$500/year + weeks
Yearly Re-certification
Annual security re-assessment to maintain verified access
Total time to production 6-12 weeks
With Unipile
Simple
Sign Up and Get API Token
Create your Unipile account and generate credentials
5 minutes
Use Hosted Auth Link
One-click Gmail connection for your users - we handle the entire OAuth flow
Instant
Start Sending and Receiving Emails
Token refresh, session persistence, reconnection - all managed automatically
1-2 days
CASA Tier 2 Certified
Google Cloud Security Assessment
Verified
Unipile is CASA Tier 2 certified - the Google-mandated security assessment for accessing restricted Gmail scopes. By using Unipile, your app benefits from our certification without going through the assessment yourself.
Skip the $500/year CASA audit - covered by Unipile
Access restricted scopes (gmail.modify, gmail.send) instantly
No yearly re-certification on your side - we handle renewals
Enterprise-ready compliance for your customers from day one
Total time to production 1-2 days
Want a full white-label experience?
You can optionally use your own Google OAuth credentials for complete branding control. Unipile guides you through the entire verification process. Read the full Google OAuth guide
Ready to ship

Stop integrating Gmail, Outlook, and IMAP one by one.

Connect any inbox in minutes through a single unified Email API. SOC 2 certified, CASA Tier 2 audited, real-time webhooks included. Start free, scale when you're ready.

SOC 2 Type II
CASA Tier 2
GDPR ready
1-2 days to prod

Frequently Asked Questions

Everything developers ask before integrating an Email API.

What is the difference between an Email API and SMTP?

SMTP is a protocol for sending emails between mail servers. An Email API is an HTTP interface that abstracts one or more underlying protocols (SMTP, IMAP, provider-native APIs) behind a REST endpoint. Email APIs add OAuth 2.0 auth, webhooks, SDKs, rate limit management, and normalized data models that SMTP alone does not provide.

Is the Gmail API free?

Yes, the Gmail API itself has no direct cost. You pay for Google Cloud infrastructure if you use Pub/Sub for push notifications, but the API quota (1 billion units per day for free accounts) is sufficient for most applications. Usage limits are per-user per-day, not global.

How do I sync an entire inbox via API?

Use a two-phase approach: initial sync (paginate through all messages) followed by incremental sync (use the Gmail historyId or the Microsoft Graph delta token to retrieve only changes since your last cycle). See the code examples in Step 4 above.

Can I send 10,000 emails per day via Email API?

It depends on the API type. Transactional sending APIs (SendGrid, Mailgun) are built for high volume and support millions of messages per day on paid plans. Inbox access APIs (Gmail API, Microsoft Graph) have per-user sending quotas (Gmail: 2,000 per day for Workspace, 500 per day for personal). For bulk campaigns, use a dedicated transactional email API, not a mailbox sync API.

Which Email API supports OAuth 2.0?

The Gmail API (Google OAuth 2.0), Microsoft Graph (Azure AD OAuth 2.0), and unified APIs like Unipile (which manages OAuth flows for all supported providers) all support OAuth 2.0. IMAP and SMTP with app passwords do not use OAuth and should be avoided for new integrations where OAuth is available.

How do I avoid rate limits when syncing emails?

Implement exponential backoff on 429 responses, use $select to request only necessary fields, batch message fetch requests where supported, and switch from polling to webhooks or push notifications for real-time updates. For Gmail, use batchModify and batchGet endpoints to reduce request counts.

What is the best Email API for SaaS?

If your SaaS product needs to connect to real user mailboxes (CRM, helpdesk, AI assistant, sales tool), a unified email sync API is the best choice: it covers all providers with a single integration. If your product only needs to send transactional emails (notifications, confirmations), a dedicated sending API like SendGrid or Resend is more appropriate.

Do I need different APIs for Gmail and Outlook?

Yes, if you integrate directly: the Gmail API and Microsoft Graph are completely separate APIs with different authentication flows, data models, and SDKs. A unified Email API like Unipile abstracts this. You integrate once and the API handles both providers transparently.

How does Unipile handle multi-provider email integration?

Unipile maintains a persistent connection to each linked account via the appropriate underlying protocol (Gmail API, Microsoft Graph, or IMAP), handles token refresh, translates provider-specific events into a normalized data model, and delivers unified webhooks to your endpoint. Your application interacts only with the Unipile REST API, never with Gmail or Microsoft Graph directly.

What about IMAP-only providers like Yahoo or ProtonMail?

Unipile supports IMAP and SMTP connections for providers that do not expose a proprietary REST API. This includes Yahoo Mail, Fastmail, ProtonMail Bridge (when the local bridge is running), and custom corporate email servers. Authentication uses app passwords or provider-specific OAuth where available.