Socket
Socket
Sign inDemoInstall

parse-smtp-unison-template

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    parse-smtp-unison-template

Parse Server Module to send emails via SMTP with individual templates


Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Install size
553 kB
Created
Weekly downloads
 

Readme

Source

About

Original Author and Project: https://github.com/macarthuror/parse-smtp-template

Customize Parse Servers default Emails

In order to use Parse Servers default Emails and customize them, you need to add the Adapter to your server configuration file like so:

var api = new ParseServer({
    appId: 'myParseHosting',
    masterKey: 'master123',
    ...
    emailAdapter: {
        module: 'parse-smtp-unison-template',
        options: {
            port: 587,
            host: "smtp.mail.com",
            user: "name@domain.com",
            password: "SecurePassword",
            fromAddress: 'app@domain.com',
            secure: true,
            templates: [
              { name: "default", path: "/views/templates/template.html", variables: { subject: "Email von Parse", username: "test@mail.de", btn: "Klicke hier", link: "https://www.google.com", appName: "default appname" } },
              { name: "verificationEmail", path: "/views/templates/verificationEmail.html", variables: { subject: "Email Adresse bestätigen", btn: "Jetzt bestätigen" } },
              { name: "passwordResetEmail", path: "/views/templates/passwordResetEmail.html", variables: { subject: "Passwort zurücksetzen", btn: "Jetzt zurücksetzen" } }
            ]
        }
    }
})

Then you need to put your .html Email Template file to the correct path. Feel free to use more templates added the same way.

The variables Object can contain any data you want to use in your email template. Once you've added it in the templates-Array, they become available as ${option.variableName} in the .html Email template file.

Send custom Emails through Parse Clode Code

You can also send emails through Parse Cloud Code by adding the adapter and then passing in variables and template names. Example:

// Define a cloud function in Parse Cloud Code named testmail
Parse.Cloud.define('testmail', async (request) => {
  // Load some variables to use in your mailings
  const courseName = 'Learn sending mails from parse';
  const courseCode = 'SM-1337';
  const semester = request.params.semester; // Variable used from the Parse Cloud request
  
  // Define the sendMail Function when we need it and set up server settings and template
  const { sendMail } = require('parse-smtp-unison-template')({
      user: 'mail@mail.com',
      password: "SecurePassword",
      fromAddress: 'app@domain.com',
      host: "smtp.mail.com",
      port: 465,
      secure: true,
      templates: [
        { name: 'invoice', path: '/views/templates/invoiceEmail.html', 'variables': { courseName, courseCode, semester } }
        // Add more Templates if you like. Careful with path to the template relative to cloud code file
        ]
  });
	
  // Set up more variables, error handling and so on, then send the email
  return sendMail({
      to: 'recipient@othermail.com',
      subject: 'Invoice for course ' + courseName,
      template: 'invoice',
      // attachments are also an option as array
  }); 
});

Then use Parse.Cloud.run('testmail') to send your mail in your SDK or other Cloud Code.

All data that you pass in through the sendMail Object overrides the ones in the template. If your template is not found, the one named "default" is used.

All data passed into the variables Object when instantiating the sendMail function overrides already set static data of the template. This is relevant when using password reset or email verify emails from parse.

You can use any variables you wish in your template, but make sure they match the ones you send in your function. E.g. the passed variable courseCode becomes available in our .html Email Template as ${option.courseCode}

Keywords

FAQs

Last updated on 15 Jun 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc