What Does "Send on Behalf" Mean in Email API?
Sending email on behalf of a user means your application dispatches messages directly from the user's own mailbox, not from a shared transactional sender. The recipient sees the user's real email address in the "From" field. This is the foundation of any SaaS product that handles email for its users.
What you will learn
Why SaaS Products Need On-Behalf Email Sending
Most SaaS products that touch email eventually face the same requirement: the user wants messages to come from their own address, not from a generic platform domain. Whether it is a CRM, an AI writing assistant, or a support tool, the moment your product sends emails for users, you need on-behalf sending. Here is why it matters - and how the three main use cases map to the API.
Sales reps send from their real Gmail or Outlook
In a CRM context, the salesperson is the one building the relationship. If your platform sends follow-ups from noreply@yourcrm.com, deliverability drops and the prospect is confused. With on-behalf sending, your CRM calls the Unipile API using the salesperson's linked account. Every email lands in the prospect's inbox showing the rep's real address.
AI drafts and sends from the user's mailbox
AI email assistants - whether they auto-draft replies, schedule follow-ups, or summarize threads - need write access to the user's mailbox. Without on-behalf sending, the AI can only suggest; it cannot execute. With a linked account via the Unipile API, your assistant can send the approved message directly from the user's Gmail or Outlook with a single API call.
Support agents reply from a shared support inbox
Customer support platforms often route tickets through a shared inbox like support@company.com. That inbox is itself a mailbox - it needs to be linked as an account. With Unipile, your platform can connect that shared Outlook or IMAP mailbox, letting any agent send replies that appear to come directly from the official support address, with full thread context preserved.
POST /api/v1/emails endpoint handles Gmail, Outlook, and IMAP accounts.How On-Behalf Email API Works (OAuth 2.0 Flow)
Sending email on behalf of a user requires three things: the user's consent, a valid access token, and a send call through the provider's infrastructure. Here is how that flow works in practice, and how Unipile abstracts it into a single unified API. For a broader technical reference on sending endpoints, parameters, and provider differences, see our complete send email API guide.
User grants OAuth permission
The user clicks "Connect your email" inside your SaaS product. Unipile redirects them to their provider's OAuth consent screen - Google for Gmail users, Microsoft for Outlook and Microsoft 365 users. The user logs in and approves the requested scopes, which include the ability to send email on their behalf. No password is ever shared with your application.
Your app receives a linked account ID
Once the user completes the OAuth flow, Unipile stores the access token securely and returns an account_id to your application. This is a stable identifier for the user's linked mailbox. You store this ID in your database against the user record. All subsequent email operations for this user reference this account_id - you never touch the raw OAuth token.
Send via the provider's infrastructure
When your application needs to send an email, it calls POST /api/v1/emails with the account_id and message payload. Unipile routes the request through the correct provider: Gmail API for Google accounts, Microsoft Graph API for Outlook and Microsoft 365 accounts, and SMTP for IMAP accounts. The email is dispatched from the user's own mailbox and appears in their Sent folder.
Code examples
import requests # account_id retrieved after user completes OAuth flow UNIPILE_DSN = "https://api1.unipile.com:13301" ACCESS_TOKEN = "YOUR_ACCESS_TOKEN" ACCOUNT_ID = "user_account_id_from_db" payload = { "account_id": ACCOUNT_ID, "to": [{ "display_name": "Sarah Connor", "identifier": "sarah@acme.com" }], "subject": "Following up on our conversation", "body": "Hi Sarah, just circling back...
" } response = requests.post( f"{UNIPILE_DSN}/api/v1/emails", json=payload, headers={"X-API-KEY": ACCESS_TOKEN} ) print(response.json()) # {"object": "EmailSent", "email_id": "..."}
// account_id retrieved after user completes OAuth flow const UNIPILE_DSN = "https://api1.unipile.com:13301"; const ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"; const ACCOUNT_ID = "user_account_id_from_db"; const payload = { account_id: ACCOUNT_ID, to: [{ display_name: "Sarah Connor", identifier: "sarah@acme.com" }], subject: "Following up on our conversation", body: "Hi Sarah, just circling back...
" }; const response = await fetch(`${UNIPILE_DSN}/api/v1/emails`, { method: "POST", headers: { "X-API-KEY": ACCESS_TOKEN, "Content-Type": "application/json" }, body: JSON.stringify(payload) }); const data = await response.json(); console.log(data); // { object: "EmailSent", email_id: "..." }
On-Behalf vs Transactional Email API: The Key Difference
These two categories of email API solve fundamentally different problems. Mixing them up is the most common mistake teams make when speccing out an email integration. Here is how they compare across every dimension that matters.
Build On-Behalf Email Sending with Unipile
Unipile provides a single unified API that abstracts Gmail, Outlook, and IMAP behind one consistent interface. You write one integration - Unipile handles provider-specific OAuth flows, token refresh, SMTP routing, and error handling for all three. Here is what is available for each provider.
Send Email On Behalf of User API - FAQ
Common questions about on-behalf email sending with Unipile
Yes, provided the user explicitly grants permission. On-behalf email sending is built on OAuth 2.0 (for Gmail and Outlook) or explicit credential sharing (for IMAP). In both cases, the user knowingly authorises your application to send from their mailbox. This is the same mechanism used by every major email client and productivity tool.
The key compliance requirements are:
- The user must actively consent before you send anything on their behalf
- Your privacy policy must disclose that you access and send from the user's mailbox
- The user must be able to revoke access at any time (OAuth revocation or account disconnection)
- You must not send content that violates the provider's terms of service (e.g. spam)
It is not legal to send from someone's address without their consent. Unipile's OAuth-based linking flow ensures you always have explicit user authorisation before any send operation.
The recipient sees the user's own domain in the From field - not your platform's domain. This is the core value proposition of on-behalf sending. For example, if a sales rep with the address john@acme.com has linked their Gmail account, every email sent through your CRM via Unipile will show From: john@acme.com.
The email is dispatched through the user's actual mail provider (Gmail API, Microsoft Graph, or SMTP), which means:
- SPF records pass because the sending IP is authorised by the user's domain
- DKIM signatures are valid because the provider signs with the user's domain key
- DMARC alignment passes for the same reasons
This is fundamentally different from a transactional API where you send from a shared infrastructure and the recipient sees your platform's domain.
The required scopes depend on the provider. Unipile handles the OAuth consent screen automatically - your users see a standard Google or Microsoft permission dialog. The exact scopes requested are:
- Gmail: the Gmail API scope that allows sending messages (
https://mail.google.com/or the more limitedgmail.sendscope if you only need send access) - Outlook / Microsoft 365: Microsoft Graph
Mail.Sendscope, plusMail.ReadWriteif you also need to read or sync the inbox - IMAP: the user provides their IMAP hostname, port, username, and either their password or an app-specific password (required for accounts with two-factor authentication enabled)
Users can revoke these permissions at any time from their Google or Microsoft account security settings, or by disconnecting the linked account inside your product.
Yes. Any mailbox that can be authenticated via OAuth or IMAP credentials can be linked as a Unipile account. This includes:
- Shared mailboxes in Microsoft 365 (e.g. support@company.com) - linked via a service account with the correct delegated permissions
- Google Workspace shared inboxes and group addresses with Send As permissions configured
- Any email alias that is handled by an IMAP-accessible mailbox
You can also customise the display name in the From field using the from parameter in the API payload, without changing the underlying sending address.
Unipile handles token refresh automatically for both Gmail and Outlook accounts. OAuth access tokens typically expire after one hour, but the refresh token is long-lived. When Unipile detects an expired access token before a send operation, it silently requests a new one using the stored refresh token - your application never sees this happen and the send call succeeds normally.
The only time you need to prompt the user to re-authenticate is if they have manually revoked access from their Google or Microsoft account settings. Unipile surfaces this as an account status change which you can detect via webhook or by polling the account endpoint.
Still have questions? Our team is here to help.