Giter Site home page Giter Site logo

node-gmail-api's Introduction

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.

Authenticating users

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.

You may use passport-google-oauth to get an access key for a user, then use this module to make requests on behalf of the authenticated user.

Example authentication call (cf. passport-google-oauth for more complete usage examples):

passport.use(new GoogleStrategy({
		clientID: config.googleApp.clientId
		, clientSecret: config.googleApp.clientSecret
		, userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
		, callbackURL: config.baseurl + '/oauth2callback'
	}
	, function(accessToken, refreshToken, profile, done) {
		// do your thing here
	}
))

Example

Fetch latest 10 emails and show the snippet

// assuming access token has already been retrieved inside variable `accessToken`

var Gmail = require('node-gmail-api')
  , gmail = new Gmail(accessToken)
  , s = gmail.messages('label:inbox', {max: 10})

s.on('data', function (d) {
  console.log(d.snippet)
})

Optionally request the fields you want (for performance)

cf. gmail API performance guide.

var Gmail = require('node-gmail-api')
  , gmail = new Gmail(accessToken)
  , 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(accessToken)
  , s = gmail.messages('label:inbox', {format: 'raw'})

s.on('data', function (d) {
  console.log(d.raw)
})

License

ISC

node-gmail-api's People

Contributors

nathanbowser avatar mef avatar sorribas avatar jangsi avatar kivill avatar roelvan avatar

Stargazers

Zo-Hasina Rasatavohary avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.