Created
August 16, 2014 12:23
-
-
Save srfrnk/fe03abd1eb62dfeea6ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("requirejs").define("models/emailHelper", [], function () { | |
var Q = require("q"); | |
var emailjs = require("emailjs"); | |
var ejs = require('ejs'); | |
var fs = require('fs'); | |
var path = require('path'); | |
return { | |
send: function (templatePath,data,to,subject) { | |
var q= Q.defer(); | |
var server = emailjs.server.connect(JSON.parse(process.env.EMAILJS_CONNECTION_OPTIONS)); | |
var str = fs.readFileSync(path.join(process.env.rootPath, templatePath), 'utf8'); | |
var html = ejs.render(str, data); | |
server.send({ | |
text: "", | |
from: "[email protected] <[email protected]>", | |
to: to, | |
subject: subject, | |
attachment: [ | |
{data: html, alternative: true} | |
] | |
}, function (err, message) { | |
if (!err) { | |
q.resolve(message); | |
} | |
else { | |
console.log(err); | |
q.reject(err); | |
} | |
}); | |
return q.promise; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment