How to use the googleapis.gmail function in googleapis

To help you get started, we’ve selected a few googleapis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dwyl / sendemail-gmail / example / server.js View on Github external
'https://www.googleapis.com/auth/plus.profile.emails.read',
  'https://www.googleapis.com/auth/calendar.readonly',
  'https://www.googleapis.com/auth/gmail.send'
];
console.log(scopes);

var opts = {
  REDIRECT_URL: '/googleauth',  // must match google app redirect URI
  handler: require('./lib/google_oauth_handler.js'), // your handler
  scope: scopes // profile
};

var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;
// var gcal = google.calendar('v3'); // http://git.io/vBGLn
var gmail  = google.gmail('v1');
var oauth2Client = new OAuth2(process.env.GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_SECRET, opts.REDIRECT_URL);
var btoa = require('btoa');

var hapi_auth_google = require('hapi-auth-google');
var sendEmail = require('../lib/sendemail_gmail');

var plugins = [
	{ register: hapi_auth_google, options:opts },
	require('hapi-auth-jwt2'),
	require('vision')
];
server.register(plugins, function (err) {
  // handle the error if the plugin failed to load:
  assert(!err, "FAILED TO LOAD PLUGIN!!! :-("); // fatal error
	// see: http://hapijs.com/api#serverauthschemename-scheme
  server.auth.strategy('jwt', 'jwt', true,
github openWMail / openWMail / mailbox / js / sync / GoogleMailboxSync.js View on Github external
"use strict"

const MMailbox = require('../models/MMailbox')
const google = require('googleapis');
const OAuth2 = google.auth.OAuth2;
const gPlus = google.plus('v1');
const gmail = google.gmail('v1');
const credentials = require('../../../credentials')

class GoogleMailboxSync {
	/***************************************************************************/
	// Lifecycle
	/***************************************************************************/
	constructor(mailboxId) {
		this.mailboxId = mailboxId
		this.googleAuthTime = undefined
		this.auth = null
		this.setupAuth()
	}

	/***************************************************************************/
	// Properties
	/***************************************************************************/
github GoogleCloudPlatform / cloud-functions-gmail-nodejs / index.js View on Github external
* you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

const google = require('googleapis');
const gmail = google.gmail('v1');
const querystring = require('querystring');
const pify = require('pify');
const config = require('./config');
const oauth = require('./lib/oauth');
const helpers = require('./lib/helpers');

/**
 * Request an OAuth 2.0 authorization code
 * Only new users (or those who want to refresh
 * their auth data) need visit this page
 */
exports.oauth2init = (req, res) => {
  // Define OAuth2 scopes
  const scopes = [
    'https://www.googleapis.com/auth/gmail.modify'
  ];
github GoogleCloudPlatform / cloud-functions-gmail-nodejs / lib / helpers.js View on Github external
* You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

const cheerio = require('cheerio');
const google = require('googleapis');
const gmail = google.gmail('v1');
const oauth = require('./oauth');
const pify = require('pify');
const Vision = require('@google-cloud/vision');
const visionClient = new Vision.ImageAnnotatorClient();

/**
 * Get base64-encoded image attachments in a GMail message
 * @param message The GMail message to extract images from
 * @returns A promise containing a list of base64-encoded images
 */
const _getImageAttachments = (message) => {
  // Get attachment data
  const attachmentIds = message.payload.parts
    .filter(x => x.mimeType && x.mimeType.includes('image'))
    .map(x => x.body.attachmentId);
github openWMail / openWMail / src / mailbox / js / sync / GoogleMailboxSync.js View on Github external
"use strict"

const MMailbox = require('../models/MMailbox')
const google = require('googleapis');
const OAuth2 = google.auth.OAuth2;
const gPlus = google.plus('v1');
const gmail = google.gmail('v1');
const credentials = require('../../../credentials')

class GoogleMailboxSync {
	/***************************************************************************/
	// Lifecycle
	/***************************************************************************/
	constructor(mailboxId) {
		this.mailboxId = mailboxId
		this.googleAuthTime = undefined
		this.auth = null
		this.setupAuth()
	}

	/***************************************************************************/
	// Properties
	/***************************************************************************/
github dwyl / sendemail-gmail / lib / sendemail_gmail.js View on Github external
var google       = require('googleapis');
var gmail        = google.gmail('v1');
var OAuth2       = google.auth.OAuth2;
var oauth2Client = new OAuth2(process.env.GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_SECRET);
var btoa         = require('btoa'); // encode email string to base64
var Handlebars   = require('handlebars');
/**
 * sendEmail abstracts the complexity of sending an email via the GMail API
 * @param {Object} options - the options for your email, these include:
 *  - credentials
 *    - {Object} auth - the list of tokens returned after Google OAuth
 *    - {Array} emails - the current user's email addresses (List)
 *  - {String} to - the recipient of the email
 *  - {String} from - sender address
 *  - {String} message - the message you want to send
 * @param {Function} callback - gets called once the message has been sent
 *   your callback should accept two arguments:
 *   @arg {Object} error - the error returned by the GMail API
github eberkund / gsuite-signature-manager / set-signature.js View on Github external
function setSignature(auth) {
  var gmail = google.gmail('v1');
  gmail.users.settings.sendAs.update({
    auth: auth,
    userId: 'me',
    sendAsEmail: 'e.berkun-drevnig@neuronicworks.com',
    resource: {
      signature: `
      Hello!!
      `
    }
  }, function(err, response) {
    if (err) {
      console.log('The API returned an error: ' + err);
      return;
    }

    //console.log(response.sendAs.find(alias => alias.isPrimary))
github SungardAS / aws-services / lib / google / gmail.js View on Github external
function _listLabels(input, callback) {

    var params = {
      auth: input.auth,
      userId: input.userId,
    };
    var self = me.listLabels;

    var gmail = google.gmail('v1');
    if (callback) {
      gmail.users.messages.list(params, callback);
      return;
    }

    self.callbackFind = function(response) {
      if (response.labels.length == 0) {
        console.log('No labels found.');
        return null;
      }
      else {
        console.log('Labels:');
        for (var i = 0; i < response.labels.length; i++) {
          var label = response.labels[i];
          //console.log('- %s', label.name);
          console.log('%s', JSON.stringify(label));
github SungardAS / aws-services / lib / google / gmail.js View on Github external
function _getMessage(input, callback) {

    var params = {
      auth: input.auth,
      userId: input.userId,
      id: input.currentMessage.id,
    };
    var self = me.getMessage;

    var gmail = google.gmail('v1');
    if (callback) {
      gmail.users.messages.get(params, callback);
      return;
    }

    self.addParams = function(response) {
      var date = response.payload.headers.filter(function(header){ return header.name=='Date';})[0].value
      console.log(date);
      var decoded = new Buffer(response.payload.body.data, 'base64').toString('ascii');
      response.payload.body.data = decoded;
      console.log(response);
      self.params.currentMessage = response;
    }

    gmail.users.messages.get(params, me.callback);
  }
github katydecorah / awaybot / src / gmail.js View on Github external
quickstart.authorize(JSON.parse(content), function updateVacation(auth) {
        const gmail = google.gmail('v1');
        const vacation = {
          enableAutoReply: true,
          responseBodyPlainText: config.vacationResponse.replace(
            /{date}/g,
            moment(date, 'YYYY-MM-DD').format('MMMM D, YYYY')
          ),
          restrictToContacts: false,
          restrictToDomain: false
        };
        gmail.users.settings.updateVacation(
          {
            auth: auth,
            userId: 'me',
            resource: vacation
          },
          (err, res) => {