How to use the googleapis.google.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 levz0r / gmail-tester / gmail-tester.js View on Github external
async function _get_recent_email(credentials_json, token_path, options = {}) {
  const emails = [];

  const query = _init_query(options);
  // Load client secrets from a local file.
  const content = fs.readFileSync(credentials_json);
  const oAuth2Client = await gmail.authorize(JSON.parse(content), token_path);
  const gmail_client = google.gmail({ version: "v1", oAuth2Client });
  const gmail_emails = await gmail.get_recent_email(
    gmail_client,
    oAuth2Client,
    query
  );
  for (const gmail_email of gmail_emails) {
    const email = {
      from: _get_header("From", gmail_email.payload.headers),
      subject: _get_header("Subject", gmail_email.payload.headers),
      receiver: _get_header("Delivered-To", gmail_email.payload.headers)
    };
    if (options.include_body) {
      let email_body = {
        html: "",
        text: ""
      };
github googleapis / google-api-nodejs-client / samples / gmail / list.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 {google} = require('googleapis');
const sampleClient = require('../sampleclient');

const gmail = google.gmail({
  version: 'v1',
  auth: sampleClient.oAuth2Client,
});

async function runSample() {
  const res = await gmail.users.messages.list({userId: 'me'});
  console.log(res.data);
  return res.data;
}

if (module === require.main) {
  const scopes = ['https://www.googleapis.com/auth/gmail.readonly'];
  sampleClient
    .authenticate(scopes)
    .then(runSample)
    .catch(console.error);
github googleapis / google-api-nodejs-client / samples / gmail / labels.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 {google} = require('googleapis');
const sampleClient = require('../sampleclient');

const gmail = google.gmail({
  version: 'v1',
  auth: sampleClient.oAuth2Client,
});

async function runSample(action, messageId, labelId) {
  if (action === 'add') {
    const res = await gmail.users.messages.modify({
      userId: 'me',
      id: messageId,
      requestBody: {
        addLabelIds: [labelId],
      },
    });
    console.log(res.data);
    return res.data;
  } else if (action === 'remove') {
github gsuitedevs / node-samples / gmail / quickstart / index.js View on Github external
function listLabels(auth) {
  const gmail = google.gmail({version: 'v1', auth});
  gmail.users.labels.list({
    userId: 'me',
  }, (err, res) => {
    if (err) return console.log('The API returned an error: ' + err);
    const labels = res.data.labels;
    if (labels.length) {
      console.log('Labels:');
      labels.forEach((label) => {
        console.log(`- ${label.name}`);
      });
    } else {
      console.log('No labels found.');
    }
  });
}
// [END gmail_quickstart]
github wavebox / waveboxapp / src / scenes / mailboxes / src / stores / google / GoogleHTTP.js View on Github external
import Bootstrap from 'R/Bootstrap'
import querystring from 'querystring'
import { google } from 'googleapis'
import FetchService from 'shared/FetchService'

const gmail = google.gmail('v1')
const oauth2 = google.oauth2('v2')
const OAuth2 = google.auth.OAuth2
const { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET } = Bootstrap.credentials

class GoogleHTTP {
  /* **************************************************************************/
  // Utils
  /* **************************************************************************/

  /**
  * Rejects a call because the mailbox has no authentication info
  * @param info: any information we have
  * @return promise - rejected
  */
  static _rejectWithNoAuth (info) {
    return Promise.reject(new Error('Mailbox missing authentication information'))
github ncent / ncent.github.io / Tools / jobcent-email / index.js View on Github external
const pubsub = new PubSub({
	keyFilename: './DevCent-998971fc504f.zßjson'
});
const subscriptionName = 'projects/devcent-1526321229076/subscriptions/newSubTest';
const subscription = pubsub.subscription(subscriptionName);
const gmailPort = 3001;

const scopes = [
                    'https://mail.google.com/',
                    'https://www.googleapis.com/auth/gmail.modify',
                    'https://www.googleapis.com/auth/gmail.readonly',
                    'https://www.googleapis.com/auth/gmail.send'
                ];

const {google} = require('googleapis');
const gmailClass = google.gmail('v1');
const oauth2Client = new google.auth.OAuth2(
  '614964866683-8pp4bakhcct0fv73hdhe8pefk0d217ol.apps.googleusercontent.com',
  '9nxp7EOkm79tp6XN38JrnsgU',
  `http://localhost:${gmailPort}/`
);
const oauthUrl = oauth2Client.generateAuthUrl({access_type: 'offline', scope: scopes});

const ncentSDK = require('../../SDK/source/ncentSDK.js');
const ncentSdkInstance = new ncentSDK();
// const masterWalletAddress = ncentSdkInstance.createWallet('an@ncnt.io');
const walletsCreated = {
    "an@ncnt.io": true
};

const alreadyProcessed = {};
let gmail;
github googleapis / google-api-nodejs-client / samples / gmail / send.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 {google} = require('googleapis');
const sampleClient = require('../sampleclient');

const gmail = google.gmail({
  version: 'v1',
  auth: sampleClient.oAuth2Client,
});

async function runSample() {
  // You can use UTF-8 encoding for the subject using the method below.
  // You can also just use a plain string if you don't need anything fancy.
  const subject = '🤘 Hello 🤘';
  const utf8Subject = `=?utf-8?B?${Buffer.from(subject).toString('base64')}?=`;
  const messageParts = [
    'From: Justin Beckwith ',
    'To: Justin Beckwith ',
    'Content-Type: text/html; charset=utf-8',
    'MIME-Version: 1.0',
    `Subject: ${utf8Subject}`,
    '',
github GTBitsOfGood / enchanted-closet / build / backend / gmailAuth.js View on Github external
function sendMessage(auth, receivers, subject, message) {
  var raw = makeBody(receivers, 'testmailec1234@gmail.com', subject, message);
  const gmail = google.gmail({
    version: 'v1',
    auth
  });
  gmail.users.messages.send({
    auth: auth,
    userId: 'testmailec1234@gmail.com',
    resource: {
      raw: raw
    }
  }, function (err, response) {
    if (err) {
      console.error(err);
    }
  });
}
github erxes / erxes-api / src / trackers / gmailTracker.ts View on Github external
const sendEmail = (integrationId: string, credentials: any, raw: string, threadId?: string) => {
  const auth = getOAuth(integrationId, credentials);
  const gmail = google.gmail('v1');

  const data = {
    auth,
    userId: 'me',
    resource: {
      raw,
      threadId,
    },
  };

  return gmail.users.messages.send(data).catch(({ response }) => {
    throw new Error(response.data.error.message);
  });
};
github ncent / ncent.github.io / Applications / jobCentEmail / index.js View on Github external
});
const subscriptionName = 'projects/jobcent-210021/subscriptions/emailWatcher';
const subscription = pubsub.subscription(subscriptionName);

const jobCentHostUrl = "http://localhost:3000/";
const gmailPort = 3001;
const app = express();

const scopes = [
                    'https://mail.google.com/',
                    'https://www.googleapis.com/auth/gmail.modify',
                    'https://www.googleapis.com/auth/gmail.readonly',
                    'https://www.googleapis.com/auth/gmail.send'
                ];
const {google} = require('googleapis');
const gmailClass = google.gmail('v1');
const oauth2Client = new google.auth.OAuth2(
  '885935339824-qgg9t6caoi4v824kvrtktcte4taf6qi1.apps.googleusercontent.com',
  'aViJjmhHPZfy85l0vDnvwl5n',
  `http://localhost:3001/`
);
const oauthUrl = oauth2Client.generateAuthUrl({access_type: 'offline', scope: scopes});

const ncentSDK = require('../../SDK/source/ncentSDK.js');
const ncentSdkInstance = new ncentSDK();
const walletsCreated = {
    "jobcent@ncnt.io": true
};


const alreadyProcessed = {};
let gmail;