parse-server-email-template-adapter

1.0.2 • Public • Published

Parse Server Email Template Adapter

npm version

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-adapter

Usage

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 <foo@example.com>"
      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));
});

/parse-server-email-template-adapter/

    Package Sidebar

    Install

    npm i parse-server-email-template-adapter

    Weekly Downloads

    0

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    21.5 kB

    Total Files

    9

    Last publish

    Collaborators

    • abdelrahman1