
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
gmail-reader
Advanced tools
A Gmail reader package for Google Workspace accounts with domain-wide delegation support
A TypeScript library for reading emails from Google Workspace (formerly G Suite) Gmail accounts. Supports both OAuth2 authentication and domain-wide delegation with service accounts.
npm install workspace-gmail-reader
import { createGmailClient, EmailQueryOptions } from 'workspace-gmail-reader';
// Create client configuration
const config = {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
redirectUri: 'your-redirect-uri' // Optional
};
// Create Gmail client
const gmailClient = createGmailClient(config, 'your-refresh-token');
// Authenticate and read emails
async function readEmails() {
await gmailClient.authenticate();
const options: EmailQueryOptions = {
maxResults: 10,
labelIds: ['INBOX'],
includeSpamTrash: false
};
const result = await gmailClient.getEmailsFrom('sender@example.com', options);
console.log(result.emails);
}
import { createDelegatedGmailClient } from 'workspace-gmail-reader';
// Create client configuration
const config = {
clientId: 'your-service-account-email',
clientSecret: '' // Not needed for domain-wide delegation
};
// Create Gmail client with domain-wide delegation
const gmailClient = createDelegatedGmailClient(
config,
'your-service-account-key-file-content',
'user-to-impersonate@your-domain.com',
['https://www.googleapis.com/auth/gmail.readonly'] // Optional scopes
);
// Authenticate and read emails
async function readEmails() {
await gmailClient.authenticate();
const result = await gmailClient.searchEmails('has:attachment');
console.log(result.emails);
}
// Get email with attachments
const email = await gmailClient.getEmail('email-id');
if (email.attachments) {
for (const attachment of email.attachments) {
const data = await gmailClient.getAttachment(email.id, attachment.attachmentId);
// data is a Buffer containing the attachment content
fs.writeFileSync(attachment.filename, data);
}
}
GmailClientThe main class for interacting with Gmail.
createGmailClient(config, refreshToken?, options?)Creates a new Gmail client for OAuth2 authentication.
createDelegatedGmailClient(config, keyFile, impersonateEmail, scopes?)Creates a new Gmail client with domain-wide delegation.
GmailClientConfiginterface GmailClientConfig {
clientId: string;
clientSecret: string;
redirectUri?: string;
}
EmailQueryOptionsinterface EmailQueryOptions {
maxResults?: number;
labelIds?: string[];
includeSpamTrash?: boolean;
q?: string;
pageToken?: string;
}
Emailinterface Email {
id: string;
threadId?: string;
subject: string;
from: string;
to: string;
date: string;
snippet: string;
body?: {
plain?: string;
html?: string;
};
attachments?: EmailAttachment[];
labels?: string[];
}
Check the examples directory for complete examples:
readFromEmail.ts: Example using OAuth2 authenticationdomainWideDelegation.ts: Example using domain-wide delegation# Install dependencies
npm install
# Build the package
npm run build
# Run tests
npm test
# Run examples
npm run example
npm run example:delegated
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
FAQs
A Gmail reader package for Google Workspace accounts with domain-wide delegation support
The npm package gmail-reader receives a total of 1 weekly downloads. As such, gmail-reader popularity was classified as not popular.
We found that gmail-reader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.