REST
email
Gmail
Read, search, and send email on behalf of the authenticated user.
Connect Gmail
Go to /dashboard/connections and click Connect on the Gmail card to grant OAuth access.
Example
List the 5 most recent messages from the last 24 hours.
app/api/recent-mail/route.ts
import { Leash } from '@leash/sdk/leash'import { NextRequest } from 'next/server'export async function GET(req: NextRequest) {const leash = new Leash({ request: req })const result = await leash.integrations.gmail.listMessages({query: 'newer_than:1d',maxResults: 5,})// result =>// {// messages: [// { id: '18f2a...', threadId: '18f2a...' },// { id: '18f28...', threadId: '18f28...' },// ...// ],// nextPageToken: '0987...'// }return Response.json(result)}
Available methods
listMessages(params?)— list messages with optionalquery,labelIds,maxResults,pageToken.getMessage(messageId, format?)— fetch a single message; format isfull,metadata,minimal, orraw.sendMessage({ to, subject, body, cc?, bcc? })— send an email as the user.searchMessages(query, maxResults?)— Gmail-syntax search (e.g.from:boss is:unread).listLabels()— list all labels for the user.getProfile()— email address and message/thread totals.
Common gotchas
- listMessages returns IDs, not bodies. Call
getMessage(id)for headers and body. - maxResults defaults to 100. Use
pageTokenfrom the previous response to paginate. - Gmail throttles aggressive sends. Batch and back off on 429.
See the Gmail API reference for the underlying provider docs.
Other languages: see SDK overview for Python and Go.