Email Services

From DreamFactory
Jump to: navigation, search
DreamFactoryFeaturesEmail Services
(Email Template Usage)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
+
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.
  
The simplest email:
+
Once configured, you can test the service via the '''API Docs''' by POSTing a request to the '''/api/v2/email''' endpoint:
 
+
`POST https://dsp-test.cloud.dreamfactory.com/api/v2/email`
+
  
 
<pre>
 
<pre>
Line 9: Line 7:
 
   "to": [
 
   "to": [
 
     {
 
     {
       "name": "Joe Blow",
+
       "name": "Joe Smith",
       "email": "joeblow@dreamfactory.com"
+
       "email": "joesmith@dreamfactory.com"
 
     }
 
     }
 
   ],
 
   ],
Line 18: Line 16:
 
</pre>
 
</pre>
  
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 [system lookups](Lookups-and-System-Variables) like {df.host_url} as well.
+
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 [[DreamFactory/Features/Lookups | Lookups and System Variables]] like '''{df.host_url}''' as well.
  
 
=== Email Template Definition ===
 
=== Email Template Definition ===
Line 26: Line 24:
 
=== Email Template Usage ===
 
=== Email Template Usage ===
  
`POST https://dsp-test.cloud.dreamfactory.com/api/v2/email`
+
To use a template, you'll POST a request to '''/api/v2/email''', including the '''template''' attribute in the request body:
  
 
<pre>
 
<pre>
Line 33: Line 31:
 
     "to": [
 
     "to": [
 
         {
 
         {
             "name": "Joe Blow",
+
             "name": "Joe Smith",
             "email": "joeblow@dreamfactory.com"
+
             "email": "joesmith@dreamfactory.com"
 
         }
 
         }
 
     ],
 
     ],
Line 40: Line 38:
 
}
 
}
 
</pre>
 
</pre>
 
==== Resulting Email Body ====
 
 
![Email Body](http://www.dreamfactory.net/dsp/images/12.png)
 

Latest revision as of 18:11, 4 June 2018

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"
}