Skip to content

m1gu3l/parse-sendgrid-mailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

parse-sendgrid-mailer

Parse.com Cloud Code module for sending emails using SendGrid API

Features

  • easy-to-use chainable API
  • no dependencies
  • sends attachments

Usage

// include mailer.js in your cloud code
var Mailer = require('path/to/mailer.js');

var mailer = new Mailer('sendgridApiUser', 'sendgridApiKey');

mailer
  .mail()
  .property('from', '[email protected]')
  .property('to', '[email protected]')
  .property('subject', 'Message with attachment')
  .property('text', 'Lorem ipsum dolor sit amet')
  .attach('hellokitty.png', 'image/png', fileBuffer)
  .send()
  .then(function(sendgridApiHttpResponse) {
    console.log('Maybe I should buy @m1gu3l a beer?');
  });

--- or ---

mailer
  .mail()
  .property('from', '[email protected]')
  .property('to', '[email protected]')
  .jsonProperty('x-smtpapi', { // https://sendgrid.com/docs/API_Reference/SMTP_API/index.html
    filters: {
      templates: {
        settings: {
          enable: 1,
          template_id: ''
        }
      }
    },
    sub: {
      '{user_firstname}': ['Receiver'],
      '{user_lastname}': ['Smith'],
      '{user_age}': ['28']
    }
  })
  .property('subject', ' ') // subject is required by SendGrid
  .property('html', ' ') // either text or html is required by SendGrid
  .send();

How to get file buffer?

Parse.Cloud.httpRequest('http://domain.net/assets/file.zip')
  .then(function(httpResponse) {
    httpResponse.buffer // <---- file contents here
  });

About

Parse.com Cloud Code module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published