Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created December 14, 2016 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnygleason/7ff37778c53d26576172314bbf2ec4a1 to your computer and use it in GitHub Desktop.
Save sunnygleason/7ff37778c53d26576172314bbf2ec4a1 to your computer and use it in GitHub Desktop.
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