All Projects → sebsylvester → Parse Server Mailgun

sebsylvester / Parse Server Mailgun

Licence: mit
Allows your Parse Server app to send template-based emails through Mailgun. Just add your template files (plain text and html) to the email adapter's configuration.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Parse Server Mailgun

wemail
Send Affordable Bulk Email Campaign Through WordPress
Stars: ✭ 19 (-64.15%)
Mutual labels:  mailgun
Grunt Email Workflow
A Grunt workflow for designing and testing responsive HTML email templates with SCSS.
Stars: ✭ 3,010 (+5579.25%)
Mutual labels:  mailgun
Mailgun Js Boland
A simple Node.js helper module for Mailgun API.
Stars: ✭ 895 (+1588.68%)
Mutual labels:  mailgun
mailcoach-support
Questions and support for Mailcoach
Stars: ✭ 32 (-39.62%)
Mutual labels:  mailgun
mailgun-plsql-api
Oracle PL/SQL API for Mailgun
Stars: ✭ 30 (-43.4%)
Mutual labels:  mailgun
Omnimail
Send email across all platforms using one interface
Stars: ✭ 325 (+513.21%)
Mutual labels:  mailgun
cakephp-mailgun
Mailgun plugin for CakePHP 3
Stars: ✭ 23 (-56.6%)
Mutual labels:  mailgun
Gympoint Api
Rest API of a gym management application - built with Express, Postgres, Redis, and Nodemailer.
Stars: ✭ 39 (-26.42%)
Mutual labels:  mailgun
Magento2 Gmail Smtp App
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Stars: ✭ 281 (+430.19%)
Mutual labels:  mailgun
Laravel Mailbox
Catch incoming emails in your Laravel application
Stars: ✭ 783 (+1377.36%)
Mutual labels:  mailgun
mailgun
Mailgun mailer adapter for Craft CMS.
Stars: ✭ 27 (-49.06%)
Mutual labels:  mailgun
bulk-mail-cli
Do quick, hassle-free email marketing with this small but very powerful tool! 🔥
Stars: ✭ 88 (+66.04%)
Mutual labels:  mailgun
Graphcool Templates
📗 Collection of Graphcool Templates
Stars: ✭ 354 (+567.92%)
Mutual labels:  mailgun
parse-server-simple-mailgun-adapter
Used to send Parse Server password reset and email verification emails though Mailgun
Stars: ✭ 81 (+52.83%)
Mutual labels:  mailgun
Laravel Mailguneu
Allow customising the Mailgun server URL to use EU servers.
Stars: ✭ 13 (-75.47%)
Mutual labels:  mailgun
lua-mailgun
Lua bindings to Mailgun HTTP API
Stars: ✭ 25 (-52.83%)
Mutual labels:  mailgun
Airform
Functional HTML forms for Front-End Developers.
Stars: ✭ 307 (+479.25%)
Mutual labels:  mailgun
Mailgun Mailer
Provides Mailgun integration for Symfony Mailer
Stars: ✭ 41 (-22.64%)
Mutual labels:  mailgun
Goeat Api
Rest API for a food delivery application - Built with Express, Postgres, Redis, MongoDB and Nodemailer
Stars: ✭ 36 (-32.08%)
Mutual labels:  mailgun
Notify
A dead simple Go library for sending notifications to various messaging services.
Stars: ✭ 727 (+1271.7%)
Mutual labels:  mailgun

parse-server-mailgun

npm version Build Status codecov

Allows your Parse Server app to send template-based emails through Mailgun. Just add your template files (plain text and html) to the email adapter's configuration.

Installation

npm install --save parse-server-mailgun

Configure test utility

To quickly test the adapter with your own Mailgun api key and domain, create a configuration file mailgun.json in the module's root directory:

Example:
{
   "apiKey": "your mailgun api key",
   "fromAddress": "Team <[email protected]>",
   "domain": "yourdomain.com",
   "host": "your.mailgun.host", // optional
   "recipient": "[email protected]",
   "username": "you",
   "appName": "YourApp"
}

Then, inside the module's root directory, run node ./src/mailgun-tester

Adapter configuration

As is the case with the default Mailgun adapter that comes with the Parse Server, you need to set a fromAddres, and the domain and apiKey provided by Mailgun. In addition, you also need to configure the templates you want to use. You must provide at least a plain-text version for each template. The html versions are optional.

const resolve = require('path').resolve;
// Note that the paths to the templates are absolute.
var server = ParseServer({
  ...otherOptions,
  // Enable email verification
  verifyUserEmails: true,
  emailAdapter: {
    module: 'parse-server-mailgun',
    options: {
      // The address that your emails come from
      fromAddress: 'YourApp <[email protected]>',
      // Your domain from mailgun.com
      domain: 'example.com',
      // Mailgun host (default: 'api.mailgun.net'). 
      // When using the EU region, the host should be set to 'api.eu.mailgun.net'
      host: 'your.mailgun.host',
      // Your API key from mailgun.com
      apiKey: 'key-mykey',
      // The template section
      templates: {
        passwordResetEmail: {
          subject: 'Reset your password',
          pathPlainText: resolve(__dirname, 'path/to/templates/password_reset_email.txt'),
          pathHtml: resolve(__dirname, 'path/to/templates/password_reset_email.html'),
          callback: (user) => { return { firstName: user.get('firstName') }}
          // Now you can use {{firstName}} in your templates
        },
        verificationEmail: {
          subject: 'Confirm your account',
          pathPlainText: resolve(__dirname, 'path/to/templates/verification_email.txt'),
          pathHtml: resolve(__dirname, 'path/to/templates/verification_email.html'),
          callback: (user) => { return { firstName: user.get('firstName') }}
          // Now you can use {{firstName}} in your templates
        },
        customEmailAlert: {
          subject: 'Urgent notification!',
          pathPlainText: resolve(__dirname, 'path/to/templates/custom_alert.txt'),
          pathHtml: resolve(__dirname, 'path/to/templates/custom_alert.html'),
        }
      }
    }
  }
});

Templates

The Parse Server only uses the MailgunAdapter for two use cases: password reset and email address verification. With a few lines of code, it's also possible to use the MailgunAdapter directly, so that you can send any other template-based email, provided it has been configured as shown in the example configuration above.

// Get access to Parse Server's cache
const { AppCache } = require('parse-server/lib/cache');
// Get a reference to the MailgunAdapter
// NOTE: It's best to do this inside the Parse.Cloud.define(...) method body and not at the top of your file with your other imports. This gives Parse Server time to boot, setup cloud code and the email adapter.
const MailgunAdapter = AppCache.get('yourAppId').userController.adapter;

// Invoke the send method with an options object
MailgunAdapter.send({
  templateName: 'customEmailAlert',
  // Optional override of your configuration's subject
  subject: 'Important: action required',
  // Optional override of the adapter's fromAddress
  fromAddress: 'Alerts <[email protected]>',
  recipient: '[email protected]',
  variables: { alert: 'New posts' } // {{alert}} will be compiled to 'New posts'
  // Additional message fields can be included with the "extra" option
  // See https://nodemailer.com/extras/mailcomposer/#e-mail-message-fields for an overview of what can be included
  extra: {
    attachments: [/* include attachment objects */]
    replyTo: 'reply-to-address'
  }
});

Version 2.4.0 switched from templating with lodash.template to using the excellent Mustache library. This allows for a lot more flexibility in your template code. For example, you can now pass an array as one of the template variables:

MailgunAdapter.send({
  //...
  variables: { 
    stooges: [
      { name: "Moe" }, 
      { name: "Larry" }, 
      { name: "Curly" }
    ]
  }
});

So that your templates can iterate over it like this:

{{#stooges}}
  <b>{{name}}</b>
{{/stooges}}

Which will result in the following output:

<b>Moe</b>
<b>Larry</b>
<b>Curly</b>

Sample templates and template variables

In the test directory, there are a few examples to get you started.

For password reset and address verification messages, you can use the following template variables by default:

  • {{{link}}} - the reset or verification link provided by the Parse Server (rendered as unescaped content)
  • {{appName}} - as is defined in your Parse Server configuration object
  • {{username}} - the Parse.User object's username property
  • {{email}} - the Parse.User object's email property

Additional variables can be introduced by adding a callback. An example is shown in the configuration above. The relevant Parse.User object is passed as an argument. The return value must be a plain object where the property names exactly match their template counterparts. Note: the callback options only applies to the password reset and email address verification use cases.

For any other use case, you use the MailgunAdapter directly and pass any variable you need to the send method as explained in the code sample above.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].