@openworkspace/gmail
v0.1.1
Published
Gmail API client for messages, threads, labels, and drafts
Maintainers
Readme
@openworkspace/gmail
Gmail API client for OpenWorkspace -- search, read, send, labels, threads, drafts.
Part of the OpenWorkspace monorepo.
Install
npm install @openworkspace/gmail @openworkspace/coreUsage
import { createHttpClient } from '@openworkspace/core';
import { searchMessages, sendMessage } from '@openworkspace/gmail';
const http = createHttpClient({ auth: { accessToken: 'token' } });
// Search messages
const result = await searchMessages(http, { query: 'from:boss' });
if (result.ok) {
for (const msg of result.value.messages ?? []) {
console.log(msg.id, msg.snippet);
}
}
// Send email
const sent = await sendMessage(http, {
to: '[email protected]',
subject: 'Hello',
body: 'Hi there!',
});API
All functions take an HttpClient as the first parameter and return Result<T, E>.
searchMessages(http, params)-- Search messagesgetMessage(http, id)-- Get a message by IDbatchModify(http, params)-- Batch modify messagesbatchDelete(http, params)-- Batch delete messagessearchThreads(http, params)-- Search threadsgetThread(http, params)-- Get a threadmodifyThread(http, params)-- Modify thread labelslistLabels(http)-- List all labelscreateLabel(http, params)-- Create a labeldeleteLabel(http, id)-- Delete a labelsendMessage(http, options)-- Send an emaillistDrafts(http, params)-- List draftscreateDraft(http, options)-- Create a draftsendDraft(http, id)-- Send a draft
