Gmail
How Does the Gmail API Send an Email?
Published 2026-09-20 · CSV Sender
Send mail with users.messages.send by building RFC 5322 MIME, base64url-encoding raw, and posting through OAuth—exactly how CSV Sender delivers each CSV row.
Quick answer
To Gmail API send email, construct a MIME message (From, To, Subject, text/plain and optional text/html parts), base64url-encode the bytes, and POST to users.messages.send with { raw: "..." }. CSV Sender reads prepared subject and body cells from each CSV row, adds promotional footers when needed, and invokes this method with the sender’s OAuth access token.
MIME construction in CSV Sender
buildMimeMessage assembles headers:
- From — display name + connected Gmail address
- To — recipient
emailcolumn - Subject — prepared subject text
- Body — plain text from CSV; HTML generated for multipart compatibility
- List-Unsubscribe — promotional campaigns only
No template language executes at this step (CSV email without templates).
messages.send request shape
Official reference (see frontmatter sources):
POST https://gmail.googleapis.com/gmail/v1/users/me/messages/send
Authorization: Bearer ACCESS_TOKEN
{ "raw": BASE64URL_ENCODED MIME }
Response includes id (provider message id) stored on the row for support correlation.
OAuth and scope
Only https://www.googleapis.com/auth/gmail.send is required for this call (Gmail send scope). Access tokens refresh automatically (OAuth access vs refresh token).
Error handling
HTTP 429 signals quota exhaustion—back off (Gmail API 429 error). 401/403 indicate auth problems (Gmail authorization expired). Invalid recipients may return 400—rows become FAILED after retries (email send retries).
Idempotency reminder
A successful messages.send followed by a worker crash must not enqueue a second send for the same row. Status guards implement idempotent email sending.
Comparison to SMTP
SMTP clients also send MIME, but over TCP with separate credentials. See Gmail API vs SMTP for CSV Sender’s choice.
Example mapping
CSV row:
email,subject,body
alex@example.com,Quarterly update,Hi Alex — here is the prepared text...
Becomes MIME To alex@example.com with exact subject/body strings at send time.
FAQ
Must raw be base64url?
Yes—Gmail API requires url-safe base64 per Google docs.
Can I set Reply-To?
Product focuses on single From mailbox—custom Reply-To would be a feature request.
Are threads preserved?
Gmail assigns threadId—CSV Sender does not manage conversation threading.
Does send read the inbox?
No (send Gmail without reading inbox).
Where is the API hub?
Related reading
Header fields CSV Sender sets
Beyond From/To/Subject, promotional sends may include List-Unsubscribe headers supporting one-click unsubscribe compliance patterns. Transactional NON_PROMOTIONAL campaigns omit marketing footers—see product message type settings when uploading.
Encoding and international characters
Prepared bodies should be UTF-8 in CSV (UTF-8 CSV email). MIME builders must encode headers correctly for non-ASCII subjects; CSV Sender handles common cases server-side so operators are not manually RFC 2047 encoding.
Debugging send failures without inbox read
Because scopes exclude read, operators cannot fetch sent message content via API for verification. Use SENT status, provider ids, and recipient confirmation. For content bugs, fix CSV and target remaining SCHEDULED rows.
Attachment policy
Attachments are not part of v1 CSV columns. If future versions add attachment URLs or base64 columns, MIME complexity and virus scanning responsibilities increase—plan accordingly.
Load testing caution
Do not point load tests at production Gmail accounts without reviewing Google quota documentation. Use small sandbox mailboxes and low caps when validating new OAuth clients.
Plain text vs HTML multipart
CSV Sender generates HTML from plain text for compatibility with clients expecting multipart/alternative structures. Operators still author plain text in CSV for simplicity (multiline text in CSV).
If future product versions accept raw HTML columns, document escaping rules clearly to avoid broken MIME or XSS in recipient clients—out of scope for v1 but common in mail merge migrations.
Production checklist (1)
Before changing live campaigns, re-verify Gmail sender CONNECTED, scan import issues, confirm suppression imports, and align dailyLimit with Gmail sending limits for CSV guidance. Prepared rows in email, subject, and body columns should pass validate CSV before emailing so queue workers spend quota on intentional mail only.
Production checklist (2)
Before changing live campaigns, re-verify Gmail sender CONNECTED, scan import issues, confirm suppression imports, and align dailyLimit with Gmail sending limits for CSV guidance. Prepared rows in email, subject, and body columns should pass validate CSV before emailing so queue workers spend quota on intentional mail only.
Sources
Related articles
Gmail
What Is the Gmail API?
The Gmail API is Google’s HTTPS JSON interface for mailbox operations. CSV Sender uses only users.messages.send with OAuth—not SMTP or inbox reads.
Gmail
What Is the gmail.send Scope?
Google’s scope table describes gmail.send as sending email on a user’s behalf. CSV Sender uses only that scope—matching lib/gmail/scopes.ts.
Gmail
Gmail API vs SMTP for Sending Email
Compare Gmail API OAuth sending with SMTP relay for CSV-based outreach—credentials, scopes, MIME, and why CSV Sender standardizes on messages.send.
CSV Email
Send Prepared Emails From a Spreadsheet Export
Treat each CSV row as a finished email—subject and body already written—and deliver through Gmail without merge templates.