Add email service, refactor Run model to use it
This commit is contained in:
32
api/services/EmailService.js
Normal file
32
api/services/EmailService.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// EmailService.js
|
||||
var sendgrid = require("sendgrid");
|
||||
|
||||
exports.sendRunEmails = function(runData) {
|
||||
var emailText = "You've been invited to " + runData.creatorName + "'s lunch run: '"
|
||||
+ runData.name + "'! \n\n Put in your order here:\nhttp://www.lunchrun.me/#/run/"
|
||||
+ runData.id + "/order/";
|
||||
var options = {
|
||||
from: runData.creatorName + " <" + runData.creatorEmail + ">",
|
||||
subject: "You've been invited to a lunch run!",
|
||||
replyto: runData.creatorEmail
|
||||
};
|
||||
|
||||
for (var idx in runData.invitees) {
|
||||
var invitee = runData.invitees[idx];
|
||||
var specificOptions = options;
|
||||
specificOptions.to = invitee.name + " <" + invitee.email + ">";
|
||||
specificOptions.text = emailText + invitee.name;
|
||||
|
||||
console.log(specificOptions);
|
||||
|
||||
sendgrid.send(specificOptions, function(err, response) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log("message sent from: " + runData.creatorEmail);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
transport.close();
|
||||
};
|
||||
Reference in New Issue
Block a user