sendgrid-parse

SendGrid Parse Cloud Module

Stars
9

SendGrid-Parse

A SendGrid Cloud Code module with X-SMTPAPI Support.

Installation

*Should soon be available in Cloud Code's env.

Example

var sendgrid = require('sendgrid');
sendgrid.initialize('SENDGRID-USERNAME', 'SENDGRID-PASSOWORD');

sendgrid.sendEmail({
	to: '[email protected]',
	from: '[email protected]',
	subject: 'Hello!',
	text: 'Hello again!'
}, {
    success: function(httpResponse) {
        console.log(httpResponse);
        response.success("Email sent!");
    },
    error: function(httpResponse) {
        console.error(httpResponse);
        response.error("Uh oh, something went wrong");
    }
});

Create Email Object

var sendgrid = require('sendgrid');
var email = sendgrid.Email({to: ['john@email', '[email protected]']});
var otherEmail = sendgrid.Email();

Adding Recipients

email.addTo('[email protected]');
email.addTo(['[email protected]', '[email protected]']);

Adding ToName

email.addToName('Jose');
email.addToName(['Jose 2', 'Happy']);

Setting From

email.setFrom('[email protected]');

Setting FromName

email.setFromName('Joseph');

Setting Subject

email.setSubject('subject');

Setting Text

email.setText('this text');

Setting HTML

email.setHTML('<b>that html</b>');

Adding BCC Recipients

email.addBcc('[email protected]');
email.addBcc(['[email protected]', '[email protected]']);

Setting Reply To

email.setReplyTo('[email protected]');

Setting Date

email.setDate(new Date().toUTCString());

Adding Files

// Parse.File Object
email.addFile('filename', file).then(function(e) {
    console.log(e);
});
// or
email.addFileFromBuffer('filename', buffer);
// or
email.addFileFromStream('filename', str);

Setting Header

email.setHeaders('some header');

Setting SMTPAPI Header

email.setAPIHeader('{sub:{key:value}}');

SendGrid's X-SMTPAPI

Substitution

email.addSubstitution('key', 'value')

Section

email.addSection('section', 'value')

Category

email.addCategory('category')

Unique Arguments

email.addUniqueArg('key', 'value')

Filter

email.addFilter('filter', 'setting', 'value')

MIT License