GmailFetch is a Node.js package that allows you to fetch and process emails from a Gmail account using the Gmail API. The package provides a simple interface to retrieve email messages, clean them, and extract relevant information such as the sender, subject, and text content. You just need to add your OAUTH credentials, tokens and number of mails to fetch and your task is done !!
To install the package, use npm:
npm install node-gmail-fetcher
Here’s how to use the node-gmail-fetcher
package:
const { GmailFetch } = require("node-gmail-fetcher");
const fetchEmails = async () => {
const gmailFetch = new GmailFetch({
accessToken: "your-access-token",
refreshToken: "your-refresh-token",
clientId: "your-client-id",
clientSecret: "your-client-secret",
mailsToFetch: 5,
});
const emails = await gmailFetch.fetchEmails();
console.log(emails);
};
fetchEmails();
[
{
id: "unique-message-id",
senderEmail: "sender@example.com",
subject: "Email Subject",
snippet: "A short snippet of the email...",
textContent: "The full text content of the email...",
},
// more emails...
];