Created
March 17, 2015 13:58
-
-
Save clarkbw/4ae97aff62df1ff6e416 to your computer and use it in GitHub Desktop.
Adding compile plugins to email transports in the Strongloop loopback boot script
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
// server/boot/email.js | |
var htmlToText = require('nodemailer-html-to-text').htmlToText; | |
var path = require('path'); | |
function templatePath (template) { | |
// this looks for templates in the root 'templates' folder where other email templates like verify.ejs exist | |
return path.join(__dirname, '..', '..', 'templates', template); | |
} | |
module.exports = function(app) { | |
var Email = app.models.Email; | |
// assign our compile plugin to all the transports we find | |
app.dataSources.MyMail.connector.transports.forEach(function (transport) { | |
transport.use('compile', htmlToText()); | |
}); | |
Email.inviteUser = function (options, next) { | |
var template = app.loopback.template(templatePath('inviteUser.ejs')); | |
var data = { to : options.to, | |
subject : options.subject, | |
html : template(options) }; | |
Email.send(data, next); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment