elbuo8 / sendgrid-parse

SendGrid Parse Cloud Module
9 stars 3 forks source link

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: 'john@email.com',
    from: 'doe@email.com',
    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', 'doe@email.com']});
var otherEmail = sendgrid.Email();

Adding Recipients

email.addTo('jose@email.com');
email.addTo(['jose2@email.com', 'happy@email.com']);

Adding ToName

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

Setting From

email.setFrom('joseph@email.com');

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('jose@email.com');
email.addBcc(['jose2@email.com', 'happy@email.com']);

Setting Reply To

email.setReplyTo('email@email.com');

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