Skip to content

Instantly share code, notes, and snippets.

@clarkbw
Created March 17, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkbw/4ae97aff62df1ff6e416 to your computer and use it in GitHub Desktop.
Save clarkbw/4ae97aff62df1ff6e416 to your computer and use it in GitHub Desktop.
Adding compile plugins to email transports in the Strongloop loopback boot script
// 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