Send Email

To send email using the dashboard, follow the steps in the Email Notification Tutorial.

For the API, you can send a message using a template via the Personalization API, or by sending the complete message via the Push API.

Create Templates

In most cases, you will create a template for your email notifications through the Personalization API. Templates support variables, so you can personalize emails for each individual recipient.

To create templates using the dashboard, follow the the Email Templates Tutorial.

Note

You can provide your own HTML email without using a template. However, you cannot personalize emails using merge fields without using a template.

Send Email Using a Template

Using the Personalization API endpoint, you can send an email specifying a template ID. The substitutions object contains the variable names (as keys) and the values you want to substitute in the template, for the audience.

Important

If your template contains merge fields, you must include all merge fields in your request or none at all.

In this example, we are targeting the named user aandersson and providing values for FIRST_NAME AND LAST_NAME keys included in the template.

Example Request With a Template
POST /api/templates/push HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3;
Content-Type: application/json

{
   "device_types": [
      "email"
   ],
   "audience": {
      "named_user": "aandersson"
   },
   "merge_data": {
      "template_id": "bde1d200-e68d-4230-bd9a-34a1939b18ff",
      "substitutions": {
         "FIRST_NAME": "Anders",
         "LAST_NAME": "Andersson"
      }
   }
}

Send Email Without a Template

When sending an email via the Push API, you must set email platform overrides such as sender_name, sender_address, etc.

Example Request Without a Template
POST /api/push HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3;
Content-Type: application/json

{
   "audience": {
      "named_user": "jane_doe"
   },
   "device_types": [
      "email",
      "android"
   ],
   "notification": {
      "android": {
        "alert": "Hello Android user!"
      },
      "email": {
        "subject": "Winter Sale!",
        "html_body": "<h1>Seasons Greetings</h1><p>Check out our winter deals!</p><p><a data-ua-unsubscribe=\"1\" title=\"unsubscribe\" href=\"http://unsubscribe.urbanairship.com/email/success.html\">Unsubscribe</a></p>",
        "plaintext_body": "Greetings! Check out our latest winter deals! [[ua-unsubscribe href=\"http://unsubscribe.urbanairship.com/email/success.html\"]]",
        "message_type": "commercial",
        "sender_name": "Urban Airship",
        "sender_address": "team@urbanairship.com",
        "reply_to": "no-reply@urbanairship.com"
      }
   }
}