Created
December 14, 2016 21:45
-
-
Save sunnygleason/7ff37778c53d26576172314bbf2ec4a1 to your computer and use it in GitHub Desktop.
PubNub Email Integration w/ Sendgrid BLOCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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