New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gmail-api-create-message-body

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gmail-api-create-message-body

Tiny utility function for creating a message body that can be used for the Gmail API upload urls

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
249
increased by43.1%
Maintainers
1
Weekly downloads
 
Created
Source

gmail-api-create-message-body

Tiny utility function for creating a message body that can be used for the Gmail API upload urls.

Example usage

var rp = require('request-promise');
var fs = require('fs');
var path = require('path');
var createBody = require('gmail-api-create-message-body');

var catBase64 = fs.readFileSync(path.join(__dirname, 'cat.png')).toString('base64');
var dogBase64 = fs.readFileSync(path.join(__dirname, 'dog.jpg')).toString('base64');

var body = createBody({
  headers: {
    To: 'receiver@gmail.com',
    From: 'sender@gmail.com',
    Subject: 'This was rad, brother.'
  },
  textHtml: 'Thanks for last time, <b>buddy.</b>',
  textPlain: 'Thanks for last time, *buddy.*',
  threadId: '1536195a8ad6a354',
  attachments: [
    {
      type: 'image/jpeg',
      name: 'dog.jpg',
      data: dogBase64
    },
    {
      type: 'image/png',
      data: catBase64
    }
  ]
});

rp({
  method: 'POST',
  uri: 'https://www.googleapis.com/upload/gmail/v1/users/me/messages/send',
  headers: {
    Authorization: 'Bearer {ACCESS_TOKEN}',
    'Content-Type': 'multipart/related; boundary="foo_bar_baz"'
  },
  body: body
});

API

/**
 * Creates a message body that can be used for the Gmail API simple upload urls.
 * @param  {object}   params
 * @param  {object}   params.[headers]            - Key-value object representing headers and their values
 * @param  {string}   params.[threadId]           - Id of the thread the message should be put into
 * @param  {string}   params.[textPlain]          - Plain text representation of the message
 * @param  {string}   params.[textHtml]           - Html text representation of the message
 * @param  {object[]} params.[attachments]        - Array of attachment objects
 * @param  {string}   params.attachments[].type   - Attachment type ('image/jpeg', 'image/png', ...)
 * @param  {string}   params.attachments[].[name] - Name of the attachment
 * @param  {string}   params.attachments[].data   - Base64 representation of the attachment data
 * @return {string}
 */
 createBody(params);

Licence

MIT

FAQs

Package last updated on 10 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc