Send an email


Email messages using API

From now on you can send email messages using our API. To do so, you'll need to set subject, content and receivers for the message.

HTML is allowed inside of email message content. For example, as a content we can set:

Hi <b>user</b>, enjoy our product!

The email message will be shown as follow:

Hi user, enjoy our product!
POST

/emails/send/

Data
Type
Description
smtp
id
ID of your SMTPSettings you want to use
subject
string
Subject for your email message
content
string
The content of your email message
campaign
integer
Email campaign ID
template
integer
Template ID
receivers
integer
Multiple receivers separated by commas
author
integer / string
This can be an email (string) or ID (integer) of an author.

ID for the receivers, can be found by requesting all, single user details or by searching his email address.

Author can determine who's the sender of this email, it can be owner or any agent of the app.

curl -X POST -H "Authorization: Token <your_64_char_api_key>" -H "Content-Type: application/json" -d '{
    "subject": "Email sent using API",
    "content": "This is content for email sent using API <a href='\''http://example.org/'\''>link</a>",
    "receivers": "5380718",
    "template": 1,
    "author": "johndoe@example.org"
}' "https://app.userengage.com/api/public/emails/send/"

Response

{
  "campaign": 880
}

This response means that the email has been sent correctly.

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://app.userengage.com/api/public/emails/send/",
  "method": "POST",
  "headers": {
    "authorization": "Token <your_64_char_api_key>",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "{\n    \"subject\": \"Email sent using API\",\n    \"content\": \"This is content for email sent using API <a href='http://example.org/'>link</a>\",\n    \"receivers\": \"5380718\",\n    \"template\": 1,\n    \"author\": \"johndoe@example.org\"\n}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var data = JSON.stringify({
  "subject": "Email sent using API",
  "content": "This is content for email sent using API <a href='http://example.org/'>link</a>",
  "receivers": "5380718",
  "template": 1,
  "author": "johndoe@example.org"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://app.userengage.com/api/public/emails/send/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("content-type", "application/json");

xhr.send(data);
var request = require("request");

var options = { method: 'POST',
  url: 'https://app.userengage.com/api/public/emails/send/',
  headers:
   { 'content-type': 'application/json',
     authorization: 'Token <your_64_char_api_key>' },
  body:
   { subject: 'Email sent using API',
     content: 'This is content for email sent using API <a href=\'http://example.org/\'>link</a>',
     receivers: '5380718',
     template: 1,
     author: 'johndoe@example.org' },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://app.userengage.com/api/public/emails/send/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n    \"subject\": \"Email sent using API\",\n    \"content\": \"This is content for email sent using API <a href='http://example.org/'>link</a>\",\n    \"receivers\": \"5380718\",\n    \"template\": 1,\n    \"author\": \"johndoe@example.org\"\n}",
  CURLOPT_HTTPHEADER => array(
    "authorization: Token <your_64_char_api_key>",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import requests

url = "https://app.userengage.com/api/public/emails/send/"

payload = "{\n    \"subject\": \"Email sent using API\",\n    \"content\": \"This is content for email sent using API <a href='http://example.org/'>link</a>\",\n    \"receivers\": \"5380718\",\n    \"template\": 1,\n    \"author\": \"johndoe@example.org\"\n}"
headers = {
    'authorization': "Token <your_64_char_api_key>",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
import http.client

conn = http.client.HTTPSConnection("app.userengage.com")

payload = "{\n    \"subject\": \"Email sent using API\",\n    \"content\": \"This is content for email sent using API <a href='http://example.org/'>link</a>\",\n    \"receivers\": \"5380718\",\n    \"template\": 1,\n    \"author\": \"johndoe@example.org\"\n}"

headers = {
    'authorization': "Token <your_64_char_api_key>",
    'content-type': "application/json"
    }

conn.request("POST", "/api/public/emails/send/", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))