Overview
The Email Service provides comprehensive email management functionality for Macro, including Gmail integration, thread management, draft handling, and email search. It manages the full email lifecycle from inbox sync to sending. Base URL:/email
Authentication: JWT authentication required. Email-specific endpoints also require a valid Gmail link via the authentication service.
Core Concepts
Links
A “link” represents a connected email account (e.g., Gmail). Each user can have multiple links. All email operations are scoped to a specific link.Threads
Emails are organized into threads (conversations). Each thread contains one or more messages and maintains metadata like read status and labels.Messages
Individual email messages within threads. Messages can be:- Inbound (received)
- Outbound (sent)
- Drafts (not yet sent)
- Scheduled (to be sent at a future time)
Threads
Get Thread Messages
Thread ID (UUID)
Pagination offset (default: 0)
Number of messages to return (default: 5, max: 100)
Array of parsed message objects
Messages are returned in order of latest updated first. The service filters messages to only those accessible by the authenticated user’s link.
List Threads
Filter by label (e.g., “INBOX”, “SENT”, “DRAFT”)
Filter to unread threads only
Number of threads to return
Pagination cursor from previous response
Update Thread
Thread ID
Mark thread as read/unread
Array of label IDs to apply
Drafts
Create Draft
Draft message object
Email subject
Array of recipient email addresses
CC recipients
BCC recipients
Plain text body
Base64-encoded HTML body
Thread ID if replying to existing thread
Message ID being replied to
Schedule send time (for scheduled emails)
Created draft with generated ID
The HTML body must be Base64-encoded (URL-safe, no padding) before sending.
Update Draft
Draft ID
Delete Draft
Send Draft
Add Attachment to Draft
Draft ID
Document ID to attach (from document storage service)
Remove Attachment from Draft
Messages
Get Message
Message ID
Send Message
Message object (same structure as draft)
Attachments
Get Attachment
Attachment ID
Signed URL to download the attachment
Original filename
File size in bytes
MIME type of the attachment
Get Attachment Document ID
Labels
List Labels
Array of label objects
Create Label
Label name
Contacts
List Contacts
Search query for contact name or email
Number of contacts to return
Array of contact objects with email, name, and interaction count
Backfill & Sync
Start Backfill
Start date for backfill (defaults to account creation)
End date for backfill (defaults to now)
Unique backfill operation ID
Get Backfill Status
Status:
pending, in_progress, completed, failed, cancelledProgress information including total and processed count
Cancel Backfill
Settings
Get Email Settings
Update Email Settings
Email signature (HTML)
Email address to automatically BCC on all sent messages
Initialize Email
Initialize Email Account
- Validates the Gmail token
- Creates initial database records
- Starts the inbox sync
Error Codes
Common Errors
400- Bad Request (validation error)401- Unauthorized (no valid link)403- Forbidden (rate limit or permissions)404- Not Found (thread/message doesn’t exist)429- Too Many Requests (rate limited by Gmail API)500- Internal Server Error
Service-Specific Error Codes
GMAIL_TOKEN_EXPIRED- Gmail access token needs refreshINVALID_RECIPIENT- One or more recipient email addresses invalidATTACHMENT_TOO_LARGE- Attachment exceeds size limitTHREAD_NOT_ACCESSIBLE- Thread belongs to different linkRATE_LIMIT_EXCEEDED- Gmail API rate limit reachedBACKFILL_IN_PROGRESS- Cannot start new backfill while one is running