Email Services

From DreamFactory
Jump to: navigation, search
DreamFactoryFeaturesEmail Services

You can set up email services to facilitate sending of emails via the REST API. Each DreamFactory Instance comes with an email service named 'Email Service' with API name of 'email'. This is the default email service and uses the email server configured in php.ini. We like to use sendmail as our default email server but you can install and use whatever you like. You can also add additional email services such as external SMTP. Enter your mail server information and credentials in the service config then POST data to that service. Go to the service in the API Docs to see the format of data that should be POSTed to the service.

Once configured, you can test the service via the API Docs by POSTing a request to the /api/v2/email endpoint:

{
  "to": [
    {
      "name": "Joe Smith",
      "email": "[email protected]"
    }
  ],
  "subject": "This is a test!",
  "body_text": "Test"
}

The posted data can also specify an email template. Templates are created and managed from the Config section of the admin console. The server will replace the lookups in the template with the data provided in the API request. In this example {first_name} in the template will be replaced with the value of first_name in the API request. The subject and body are stored in the template. You can use Lookups and System Variables like {df.host_url} as well.

Email Template Definition

Email template definition.png

Email Template Usage

To use a template, you'll POST a request to /api/v2/email, including the template attribute in the request body:

{
    "template": "test_template",
    "to": [
        {
            "name": "Joe Smith",
            "email": "[email protected]"
        }
    ],
    "first_name": "Joe"
}