node package manager

node-gmail-api

node-gmail-api

Node module to interact with the gmail api

Why not the google official library? Well it does too much and doesn't implement batching. Which means fetching a bunch of email is insanely painful. This module exposes a function which will query the api searching for messages and hit the google batch api to fetch all the messages that are returned.

To use this module, you'll need an oauth access token key. See more details here: https://developers.google.com/gmail/api/overview#auth_and_the_gmail_api

We use node-passport to get an access key for a user, then use this module to make requests on behalf of the authenticated user.

Example

// Fetch latest 10 emails and show the snippet
 
var Gmail = require('node-gmail-api')
  , gmail = new Gmail(<KEY>)
  , s = gmail.messages('label:inbox', {max: 10})
 
s.on('data', function (d) {
  console.log(d.snippet)
})
// Optionally request the fields you want (for performance)
// https://developers.google.com/gmail/api/guides/performance
 
var Gmail = require('node-gmail-api')
  , gmail = new Gmail(<KEY>)
  , s = gmail.messages('label:inbox', { fields: ['id', 'internalDate', 'labelIds', 'payload']})
 
s.on('data', function (d) {
  console.log(d.id)
})
// Optionally request the format you want (e.g full (default), raw, minimal, metadata)
 
var Gmail = require('node-gmail-api')
  , gmail = new Gmail(<KEY>)
  , s = gmail.messages('label:inbox', {format: 'raw'})
 
s.on('data', function (d) {
  console.log(d.raw)
})

License

ISC