UNPKG

@cgignite/ignite-sendgrid

Version:

Send Grid node allows you to send email within your Ignite APIs and apps via Send Grid

64 lines (62 loc) 1.7 kB
module.exports = function(RED) { const axios = require('axios'); function sendGrid(config) { RED.nodes.createNode(this, config); const node = this; node.sgconfig = RED.nodes.getNode(config.sendgridconfig); this.on('input', function (msg) { axios({ method: 'post', url: 'https://api.sendgrid.com/v3/mail/send', headers : {"Authorization" : "Bearer " + node.sgconfig.credentials.apikey}, data: { "from":{ "email":node.sgconfig.from }, "personalizations":[ { "to":[ { "email":msg.payload.to } ], "dynamic_template_data":msg.payload.data } ], "template_id":node.sgconfig.templateid } }).then(function(r){ node.send({ status : r.status, statusText : r.statusText }) }) .catch(function(e){ node.send({ status : e.response.status, statusText : e.response.statusText, data : e.response.data, config : e.response.config }); }); // client.setApiKey(node.apikey); // console.log(node.apikey); // var request = { // method: 'GET', // url: '/v3/api_keys' // }; // client.request(request) // .then(function(r){ // if(r[0].statusCode == 200) // { // node.send(r[0].body.result); // } // }).catch(function(e){ // node.send(e); // }); }); } RED.nodes.registerType('send grid', sendGrid); };