Mail API

All databases have a REST endpoint for sending emails. Email sending is relayed and copies are stored in a database system collection called email_outbound.

Connect your Mailgun account

mailgun logo

Set up your own account at Mailgun. They have a free trial plan. After you've added your account, add your domain and apikey in the Settings. That's all there is to do.

All outbound email from your database will now be securely relayed via your own Mailgun account.

settings tab

  "mailgun": {
    "domain": "",
    "apikey": "xxxyyyzzz"


This example sends an email to a client from an imaginary database mydatabase-ad0c. The REST endpoint for sending email would then be:

The request.body should contain the email fields that are used to send the mail.

Request body example:

    "subject":"Your order is ready", 
    "html": "<p>Lorem ipsum dolor..., <b>vel</b> luctu.</p>", 
    "company": "Acme Inc", 
    "sendername": "Acme customer support"

HTTP example:

POST /mail HTTP/1.1
Content-Type: application/json
x-apikey: 588ca78ff2c06c15467a12cc
Cache-Control: no-cache

{"to":"","subject":"Your order is ready", "html": "<p>Lorem ipsum dolor sit amet... suscipit quis, <b>vel</b> luctu.</p>", "company": "Acme Inc", "sendername": "Acme customer support"}

The output from the example above looks something like this screenshot:

screen shot

Mail API

Http VerbResourceFunctionality
POSThttps://<dburl> email. Request body contains one JSON document, or array (max 1000) of JSON documents:
{"to": "...", "subject": "...", "html": "..." ,[options]}


Allowed properties in a mail JSON body:

to"to": ""One email address. Must be a valid email address. Not allowed with multiple spearated with space, comma or semicolon.
subject"subject": "Important subject"Email subject field.
html"html": "<p>Hi there …</p>"A html email message. When using a custom template this value must be a JSON document. E.g. {"body": "<p>Hi there …</p>", "a-field": "a-value", …}
company"company": "Acme"Add the company name to the default template footer.
sendername"sendername": "Customer support"Hides the from email address, and use a friendly name instead. Works in most email client applications.
transport"transport": "Gmail"Use Gmail SMTP as transport. Require a paid plan.
template"template": "<MyPageName>"Use a Custom Page as email template. Replaces {{name}} with values from the html property. Require a paid plan.


Pages can be used to automate and customize your emails. Pages are plain HTML with Handlebars tags for dynamic fields.

E.g. this simple Page template:

pahe template

Sending emails with templates is an extra option ("template": "<name>") provided in the API. It's also important to notice that the email message is not a text string, but a JSON object with the dynamic fields that will be replaced with the Page template field.

    "subject":"Trigger email from you database", 
    "html": {"name":"Jones", "body": "..."}, 
    "company": "Acme Inc", 
    "sendername": "Acme support",
    "template": "MyTemplate"

In this example, we've used an email template from The resulting email will then look something like this:

email template example result


gmail logo

You can also use your own Gmail account for sending email (only for paid plans). Follow the steps below to set this up.

Database settings

To use Google as smtp transport you need to store your username and passord in the database settings. In Development mode, navigate to the Settings tab (from the top level) and add the following JSON setting: settings tab

  "restdb": {
    "Gmail-service": {
      "auth": {
        "user": "<your gmail email address>",
        "pass": "<your gmail password>"

Important: override security settings on GMail account

Gmail does not accept to relay smtp email based on username and password by default. To override this, navigate on your Gmail account to: My account / Sign-in & security / Connected apps & sites. Then click the setting to ON for allowing access from your database:

gmail settings Important: we strongly recommend to create a separate Gmail account for relaying smtp email.

Sending email with Gmail transport

The only difference from sending mail with Gmail is that you need to provide this as a property on the mail JSON document:

  "transport": "gmail",
    "subject":"Your order is done", 
    "html": "<h2>Lorem ipsum dolor</h2><p>..., <b>vel</b> luctu.</p><p>Greetings from the team :)</p>", 
    "company": "Acme Inc", 
    "sendername": "Acme customer support"

This example email results in the following email to the user: gmail screen shot