New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

gmail-api-node

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gmail-api-node

Gmail api wrapper

latest
Source
npmnpm
Version
1.1.6
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

gmail-api

This module is designed to make Gmail api interaction easier using google-api-nodejs-client. Note that the module is under development and have no many methods at this moment.

Intallation

npm install gmail-api-node

Auth

Before any interaction you need to retreive a session token, so you can do it in two ways:

1. Use an existing token

const token = {
        "access_token": "TOKEN",
        "refresh_token": "TOKEN",
        "scope": "https://www.googleapis.com/auth/gmail.modify",
        "token_type":"Bearer",
        "expiry_date":1654000000000
};

const gmail = new Gmail({
    client_secret: process.env.CLIENT_SECRET,
    client_id: process.env.CLIENT_ID,
    redirect_uris: [ "http://localhost:3000" ],
    token
});

await gmail.authorize()

2. Create a new token

const gmail = new Gmail({
    client_secret: process.env.CLIENT_SECRET,
    client_id: process.env.CLIENT_ID,
    redirect_uris: [ "http://localhost:3000" ],
});

const authUrl = gmail.authUrl;

// go to url and return the given code

const code = getCode() // Feel free to get the code from user in any way.

await gmail.authorize(code);

// the token is created, you can store it to reuse it by using the first method
const token = gmail.token

Retrieve mails

Here is an example for retrieving the first 10 mails from inbox

    const messages = await gmail.listMessages({
        userId: "me",
        maxResults: 10,
        q: "label:inbox"
    });

    // fetch data from message (author, subject, body...)
    await Promise.all(messages.map(async message => message.fetch()));
    
    console.log(messages)

Keywords

gmail

FAQs

Package last updated on 04 Sep 2022

Did you know?

Socket

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.

Install

Related posts