HTML emails, fixes formatting

This commit is contained in:
Ben Ramey
2014-07-04 14:55:20 -05:00
parent 353ffcf8dd
commit 303254ce9d
4 changed files with 38 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
// EmailService.js // EmailService.js
var sendgrid = require("sendgrid"); var sendgrid = require("sendgrid");
var thenJade = require("then-jade");
exports.sendOrderEmail = function(inviteeData) { exports.sendOrderEmail = function(inviteeData) {
Run.findOne({ id: inviteeData.run_id }, function(err, runData) { Run.findOne({ id: inviteeData.run_id }, function(err, runData) {
@@ -8,29 +9,36 @@ exports.sendOrderEmail = function(inviteeData) {
return; return;
} }
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/#/order/"
+ inviteeData.id;
var options = { var options = {
fromname: runData.creatorName + " via LunchRun.me", fromname: runData.creatorName + " via LunchRun.me",
from: sails.config.email.fromAddress, from: sails.config.email.fromAddress,
to: inviteeData.email, to: inviteeData.email,
toname: inviteeData.name, toname: inviteeData.name,
subject: "You've been invited to a lunch run!", subject: "You've been invited to a lunch run!",
replyto: runData.creatorEmail, replyto: runData.creatorEmail
text: emailText
}; };
var sg = sendgrid(sails.config.email.apiUser, sails.config.email.apiKey);
sg.send(options, function(err, response) { thenJade.renderFile(
if (err) { './views/emails/new-invitee.jade',
console.log(err); { runData: runData, inviteeData: inviteeData },
} else { function(err, result) {
console.log("message sent from: " + runData.creatorEmail + ", to: " + inviteeData.email); if (err) {
} console.log(err);
}); return;
}
console.log(options); options.html = result;
var sg = sendgrid(sails.config.email.apiUser, sails.config.email.apiKey);
sg.send(options, function(err, response) {
if (err) {
console.log(err);
} else {
console.log("message sent from: " + runData.creatorEmail + ", to: " + inviteeData.email);
}
});
console.log(options);
});
}); });
}; };

View File

@@ -4,5 +4,5 @@
module.exports.email = { module.exports.email = {
apiUser: "benjaminramey", apiUser: "benjaminramey",
apiKey: "AVidasUPthub6pY3fFGe", apiKey: "AVidasUPthub6pY3fFGe",
fromAddress: "ben.ramey@gmail.com" fromAddress: "no-reply@lunchrun.me"
}; };

6
views/emails/layout.jade Normal file
View File

@@ -0,0 +1,6 @@
doctype html
html(lang="en")
head
body
block content

View File

@@ -0,0 +1,8 @@
extends layout
block content
p= "You've been invited to " + runData.creatorName + "'s lunch run: " + runData.name + "!"
p
a(href='http://www.lunchrun.me/#/order/' + inviteeData.id) Put in your order!