GithubHelp home page GithubHelp logo

lvim-tech / parse-mail-adapter-smtp-ejs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aclec/parse-mail-adapter-smtp-ejs

0.0 0.0 0.0 35 KB

Parse Server Mail Adapter with EJS templates (SMTP)

License: MIT License

TypeScript 38.31% HTML 61.69%

parse-mail-adapter-smtp-ejs's Introduction

parse-mail-adapter-smtp-ejs

Parse Server Mail Adapter with EJS templates (SMTP)

Installation

Install npm module in your parse server project

$ npm install --save parse-mail-adapter-smtp-ejs
$ yarn add parse-mail-adapter-smtp-ejs

Use

"use strict";

const Express = require('express');
const ParseServer = require('parse-server').ParseServer;

const app = Express();
const APP_PORT = 8080;


let api = new ParseServer({
    appName: "Parse Test",
    appId: "appid",
    masterKey: "secret",
    serverURL: "http://localhost:8080/parse",
    publicServerURL: "http://localhost:8080/parse",
    databaseURI: "mongodb://user:pass@host:27017/parse",
    port: APP_PORT,
    //This is the config for email adapter
    emailAdapter: {
        module: "parse-mail-adapter-smtp-ejs",
        options: {

            nodeMailerOptions: {
                host: 'your.smtp.host',
                port: 465,
                secure: true, //True or false if you are using ssl 
                auth: {
                    user: '[email protected]',
                    pass: 'AwesomePassword',
                }
                // you can add here other custom props for nodemailer like "tls"...
            },

            defaultFrom: '[email protected]', // Use for ResetPassword, VerifyEmail

            templatesOptions: {
                locales: ["en", "fr"],
                defaultLocale: "en",
                templatesDir: __dirname + '/templates/',

                templates: {
                    //This template is used only for reset password email
                    //The locale used for these templates is the one of user.get("locale") or the default locale
                    resetPassword: {
                        //Name to your template
                        template:'reset-password.html',
                        //Subject for this email
                        subject: 'Reset your password'
                    },
                    verifyEmail: {
                        template: 'verify-email.html',
                        subject: 'Verify Email'
                    }
                }
            }
            
        }
    }
});


app.use('/parse', api);

app.listen(APP_PORT, function () {
	console.log(`Parse Server Ready and listening on port ${APP_PORT}`);
});

Template

Architecture

templates/
└── en/                 // en locale folder
   └── example.html    // en localized file
└── fr/                 // fr locale folder
   └── example.html    // fr localized file

Variables (resetPassword & verifyMail)

  • appName //This is the name of your parse app
  • link //This is the link for reset the password
  • user //This is a Parse object of the current user

Send Mail From Cloud Code

=> Parse Server >= 5.0.0

Parse.Cloud.sendEmail({
    template: "myTemplate.html", // Email Html
    locale: "en",
    from: "[email protected]",
    to: "[email protected]",
    subject: "my Subejct",
    text: "", // Email Text
    data: {} // data gives to ejs
});

=> Parse Server < 5.0.0

// Import on top
const { AppCache } = require('parse-server/lib/cache');

// To use in code
const MailAdapter = AppCache.get('appid').userController.adapter;
await MailAdapter.sendMail({
    template: "myTemplate.html", // Email Html
    locale: "en",
    from: "[email protected]",
    to: "[email protected]",
    subject: "my Subejct",
    text: "", // Email Text
    data: {} // data gives to ejs
});

License MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.