A SendGrid Cloud Code module with X-SMTPAPI Support.
*Should soon be available in Cloud Code's env.
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");
}
});
var sendgrid = require('sendgrid');
var email = sendgrid.Email({to: ['john@email', 'doe@email.com']});
var otherEmail = sendgrid.Email();
email.addTo('jose@email.com');
email.addTo(['jose2@email.com', 'happy@email.com']);
email.addToName('Jose');
email.addToName(['Jose 2', 'Happy']);
email.setFrom('joseph@email.com');
email.setFromName('Joseph');
email.setSubject('subject');
email.setText('this text');
email.setHTML('<b>that html</b>');
email.addBcc('jose@email.com');
email.addBcc(['jose2@email.com', 'happy@email.com']);
email.setReplyTo('email@email.com');
email.setDate(new Date().toUTCString());
// Parse.File Object
email.addFile('filename', file).then(function(e) {
console.log(e);
});
// or
email.addFileFromBuffer('filename', buffer);
// or
email.addFileFromStream('filename', str);
email.setHeaders('some header');
email.setAPIHeader('{sub:{key:value}}');
email.addSubstitution('key', 'value')
email.addSection('section', 'value')
email.addCategory('category')
email.addUniqueArg('key', 'value')
email.addFilter('filter', 'setting', 'value')