parse-server-email-template-adapter
v1.0.2
Published
parse server email adapter for sending html emails templates
Maintainers
Readme
Parse Server Email Template Adapter
parse email adapter for sending html email templates with parse platform like (verificationEmail, passwordResetEmail) or a custom email template. this adapter uses nodemailer as a dependancy.
for more about parse server: https://github.com/parse-community/parse-server.
Installation
$ npm install --save parse-server-email-template-adapterUsage
adapter.js
//adapter options
const options = {
// ... nodemailer options,
templates: {
verificationEmail: path.join(__dirname, templatePath),
passwordResetEmail: path.join(__dirname, templatePath)
}
};
//import the module and pass the options
const adapter = require("parse-server-email-adapter")({...opt});
//export the options to be used in the parse server config
//export the sendMail function to be used in sending emails in cloud code
module.exports = {
adapter.sendMail,
options,
};parse server config
const path = require("path");
const mailAdapter = require(/*adapter.js path*/);
const parse = new ParseServer({
//...parse config
emailAdapter: {
module: "parse-server-email-template-adapter",
options: {
...mailAdapter.options
}
}
});cloud code /cloud/main.js
const mailAdapter = require(/*adapter.js path*/);
const path = require("path");
Parse.Cloud.define("sendMail", (req, res) => {
mailAdapter
.sendMail({
to: req.params.to, // "foo <[email protected]>"
subject: req.params.subject, // email subject
template: path.join(__dirname /*template path*/),
templateData: {
/*template data*/
} // now you can use {{paramater}} in your template
})
.then(info => res.success("success"))
.catch(err => res.error(err));
});