// EmailService.js var sendgrid = require("sendgrid")(sails.config.email.apiKey); var thenJade = require("then-jade"); exports.sendOrderEmail = function(inviteeData) { Run.findOne({ id: inviteeData.run_id }, function(err, runData) { if (err) { console.log(err); return; } var options = { fromname: runData.creatorName + " via LunchRun.me", from: sails.config.email.fromAddress, to: inviteeData.email, toname: inviteeData.name, subject: "You've been invited to a lunch run!", replyto: runData.creatorEmail }; thenJade.renderFile( './views/emails/new-invitee.jade', { runData: runData, inviteeData: inviteeData }, function(err, result) { if (err) { console.log(err); return; } options.html = result; sendgrid.send(options, function(err, response) { if (err) { console.log(err); } else { console.log("message sent from: " + runData.creatorEmail + ", to: " + inviteeData.email); } }); console.log(options); }); }); };