Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PubNub Email Integration w/ Sendgrid BLOCK
function process(request) {
var console = require('console');
var xhr = require('xhr');
var query = require('codec/query_string');
var apiUrl = 'https://api.sendgrid.com/api/mail.send.json';
var apiUser = 'your_username';
var apiKey = 'your_pass';
var senderAddress = 'your_sender_address@gmail.com';
try {
// create a HTTP GET request to the sendgrid API
return xhr.fetch(apiUrl + '?' + query.stringify({
api_user: apiUser, // your sendgrid api username
api_key: apiKey, // your sendgrid api password
from: senderAddress, // sender email address
to: request.message.to, // recipient email address
toname: request.message.toname, // recipient name
subject: request.message.subject, // email subject
text: request.message.text + // email text
'\n\nInput:\n' + JSON.stringify(request.message, null, 2)
})).then(function (res) {
console.log(res);
return request;
});
} catch (e) {
console.log(e);
return request;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment