parse-server-sendmail-template-adapter
This mail adapter for Parse Server uses sendmail to send emails.
This code is inspired by parse-server-sendmail-adapter.
Installation
Put parse-server-sendmail-template-adapter
in the dependencies object of
your project's package.json
file.
"dependencies":
Usage
The initializer takes a single object parameter with the following fields:
Field Name | Description |
---|---|
fromAddress |
the address to send from (i.e. noreply@yourdomain.com) |
verificationSubject |
the subject for new account verification emails |
verificationBody |
the body for new account verification emails (inline text or a filename) |
passwordResetSubject |
the subject for password reset emails |
passwordResetBody |
the body for password reset emails (inline text or a filename) |
userFields |
the custom items from the user object to pull for use in templates |
fromAddress
is the only required field to get setup.
mailAdapter
object
For readability I confine all the mail adapter configuration items for parse
servers in their own object called emailAdapter
that I then supply to the
server's constructor.
var server = // sends a verification when users add and email to their account verifyUserEmails: true // the amount of time they have to reset their password in seconds emailVerifyTokenValidityDuration: 2 * 60 * 60 // the settings for the mail adapter for the server emailAdapter: emailAdapter;
Here are some examples of how to set up the emailAdapter
object using this
mail adapter with text files, HTML templates, or inline strings.
Simple example
This example uses the default verification and password reset subjects and bodies.
var emailAdapter = module: options: fromAddress: 'noreply@test.domain.com' ;
Example using file bodies and inline subjects
This example uses HTML files as templates for the body.
var emailAdapter = module: options: fromAddress: 'noreply@test.domain.com' verificationSubject: 'Confirm your %appname% account' verificationBody: 'templates/inlined/verify_email.html' passwordResetSubject: 'Reset your %appname% password' passwordResetBody: 'templates/inlined/reset_password.html' ;
Example using inline fields
This example uses inline strings to define the body contents of the emails.
var emailAdapter = module: options: fromAddress: 'noreply@test.domain.com' verificationSubject: 'Confirm your %appname% account' verificationBody: `Hi, You are being asked to confirm the e-mail address %email% with %appname% Click here to confirm it: %link%` passwordResetSubject: 'Reset your %appname% password' passwordResetBody: `Hi, You requested a password reset for %appname%. Click here to reset it: %link%` ;
Templates
The adapter uses templating to use generalized email formats to provide unique information to users. By default there are 4 items that can be used in templates:
Template Key | Description |
---|---|
%appname% |
The name of the app as it appears in the Parse Server configuration |
%link% |
The unique link to provide in the email for web app feature integration |
%username% |
The username of the user receiving an email |
%email% |
The email address of the user receiving an email |
Example using custom user fields in templates
This example uses custom fields from the user object in its templates. to
access the dynamic values in userField
in a template, surround it with %s.
i.e. if a user is sent an email using the following template it would be
replaced with items from the user object.
- Hi %firstName% %lastName%! -> Hi Jacob Smith!
var emailAdapter = module: options: fromAddress: 'noreply@test.domain.com' userFields: "firstName" "lastName" ;