1.1.6 • Published 2 years ago

gmail-api-node v1.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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)
1.1.6

2 years ago

1.1.5

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago