Merge branch 'sendgrid' into develop
This commit is contained in:
@@ -5,8 +5,6 @@
|
|||||||
* @description :: A short summary of how this model works and what it represents.
|
* @description :: A short summary of how this model works and what it represents.
|
||||||
* @docs :: http://sailsjs.org/#!documentation/models
|
* @docs :: http://sailsjs.org/#!documentation/models
|
||||||
*/
|
*/
|
||||||
var nodemailer = require('nodemailer');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
attributes: {
|
attributes: {
|
||||||
@@ -32,40 +30,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
afterCreate: function(values, next) {
|
afterCreate: function(values, next) {
|
||||||
var transport = nodemailer.createTransport('SMTP', {
|
EmailService.sendRunEmails(values);
|
||||||
service: "Gmail",
|
|
||||||
auth: {
|
|
||||||
user: "ben.ramey@gmail.com",
|
|
||||||
pass: "dxir9PwxRwh9tauwcEbj"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var emailText = "You've been invited to " + values.creatorName + "'s lunch run: '"
|
|
||||||
+ values.name + "'! \n\n Put in your order here:\nhttp://www.lunchrun.me/#/run/"
|
|
||||||
+ values.id + "/order/";
|
|
||||||
var options = {
|
|
||||||
from: values.creatorName + " <" + values.creatorEmail + ">",
|
|
||||||
subject: "You've been invited to a lunch run!"
|
|
||||||
};
|
|
||||||
|
|
||||||
for (var idx in values.invitees) {
|
|
||||||
var invitee = values.invitees[idx];
|
|
||||||
var specificOptions = options;
|
|
||||||
specificOptions.to = invitee.name + " <" + invitee.email + ">";
|
|
||||||
specificOptions.text = emailText + invitee.name;
|
|
||||||
|
|
||||||
console.log(specificOptions);
|
|
||||||
transport.sendMail(specificOptions, function(err, response) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
} else {
|
|
||||||
console.log("message sent from: " + values.creatorEmail);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
transport.close();
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
33
api/services/EmailService.js
Normal file
33
api/services/EmailService.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// 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
|
||||||
|
};
|
||||||
|
var sg = sendgrid(sails.config.email.apiUser, sails.config.email.apiKey);
|
||||||
|
|
||||||
|
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();
|
||||||
|
};
|
||||||
7
config/email.js
Normal file
7
config/email.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
//
|
||||||
|
// Configuration for EmailService
|
||||||
|
//
|
||||||
|
module.exports.email = {
|
||||||
|
apiUser: "benjaminramey",
|
||||||
|
apiKey: "AVidasUPthub6pY3fFGe"
|
||||||
|
};
|
||||||
@@ -11,9 +11,9 @@
|
|||||||
"then-jade": "1.1.0",
|
"then-jade": "1.1.0",
|
||||||
"sails-mongo": "latest",
|
"sails-mongo": "latest",
|
||||||
"mongodb": "latest",
|
"mongodb": "latest",
|
||||||
"nodemailer": "~0.6.1",
|
|
||||||
"load-grunt-tasks": "~0.3.0",
|
"load-grunt-tasks": "~0.3.0",
|
||||||
"glob": "3.2.8",
|
"glob": "3.2.8",
|
||||||
|
"sendgrid": "1.0.2",
|
||||||
"grunt-contrib-clean": "~0.5.0",
|
"grunt-contrib-clean": "~0.5.0",
|
||||||
"grunt-contrib-copy": "~0.5.0",
|
"grunt-contrib-copy": "~0.5.0",
|
||||||
"grunt-contrib-concat": "~0.3.0",
|
"grunt-contrib-concat": "~0.3.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user