This section applies to Rebar only.


The unit for sending e-mail is based on the service provided by Send Grid. It takes care of sending email and error handling.



In /configuration/units/rb-email/server/settings.js populate the EmailRecipientSubstitution setting with rules for replacement of an email recipient. This setting is useful in a development environment, where during testing one would like all emails to be sent to only one E-Mail address instead of E-Mail addresses of real users.

In the example below, for development environment (as specified by NODE_ENV), we would send all emails to

export const EmailRecipientSubstitution = {
  'development': [
    { match: /[\s\S]*/, replacement: '' }

Account setup

In your account in Send Grid, create a new API key at Configure the API key to send email:

SendGrid API creation

Your key will be displayed once the API key is generated:

SendGrid API key

Notice that once you close the page you would not be able to retrieve the key again. Make sure to record it properly.

In .env specify:

EMAIL_SENDGRID_API_KEY=<value of the App key above>


In order to send HTML mail you would need a template file:

<!-- SendEmail.ejs -->

  Hello <%- userDisplayName %>.
  The World is ready to see you!

In order to send an email based on the template, use:

// SendEmail.js

// ...
import EmailSender from '../../../units/rb-email/server/emailSender'
// ...

  '',    // To
  '',          // From
  'hello world',                       // Subject
  '/path/to/SendEmail.ejs',            // Path to email template
  { userDisplayName: 'John Doe' }      // Template parameters

In the example above the template has one parameter, userDisplayName, which is passed to it. If the template can not be parsed and processed, an error will be written into the log and no email will be sent.