Sending Parse Server’s password reset and user validation emails using Mandrill with templates.

Sending Parse Server’s password reset and user validation emails using Mandrill with templates.

The necessity of sending emails with Mandrill in a Parse Server based application raised. It was easy to integrate Mandrill with Parse Server to send emails thanks to the NodeJS API offered by Mandrill, but we faced the difficulty of integrating the templating functionality with the (really) easy to use password reset and email validation stock functionalities offered by Parse.

We decided to contribute with Back4app’s parse-server-mandrill-adapter package adding it support for Mandrill Templates.

How to use it

  1. Create a template for Mandrill (you can use Mailchimp) and make sure it includes the merge tag `*|link|*` somewhere in it. You can also include the following merge tags:
  2. *|appname|*
  3. *|email|*
  4. *|username|*
  5. Any custom attribute of your Parse User class (must be written exactly equal to your attribute’s key).
  6. In your server’s project.
  7. npm install --save parse-server-mandrill-adapter
  8. In the main file of your project configure the email adapter:
				
					var api = new ParseServer({
  ...
  verifyUserEmails: true,
  publicServerURL: 'http://...',
  appName: 'My App',

  // The email adapter
  emailAdapter: {
    module: 'parse-server-mandrill-adapter',
    options: {
      // API key from Mandrill account
      apiKey: 'your-mandrill-api-key',
      // From email address
      fromEmail: 'reset@your.domain',
      // Display name
      displayName: 'reset@your.domain',
      // Reply-to email address
      replyTo: 'reset@your.domain',
      // Verification email subject
      verificationSubject: 'Please verify your e-mail for *|appname|*',
      // Password reset email subject
      passwordResetSubject: 'Password Reset Request for *|appname|*',

      // The extra User attributes you want to render in your email must be included here:
      customUserAttributesMergeTags: ['firstname', 'lastname'],

      // The name of your Mandrill template for the password reset email.
      passwordResetTemplateName: 'password-reset-mandrill-template-name',

      // The name of your Mandrill template for the verification email.
      verificationTemplateName: 'email-verification-mandrill-template-name',

    }
  }
  ...
});
				
			

And that’s it!

Now your email verification and password reset emails will be sent using your templates.

We hope you find it useful and please, contact us if you have any comments or questions!

See related posts