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. If you want to send your messages using specific settings, you should specify smtp id, or campaign id, otherwise we will use our default smtp to deliver your messages.

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/campaign
integer
ID of your SMTPSettings or Campaign, you want to use as a setting for sending messages
subject
string
Subject for your email message
content
string
The content of your email message
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://<your_app_subdomain>.user.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://<your_app_subdomain>.user.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://<your_app_subdomain>.user.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://<your_app_subdomain>.user.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://<your_app_subdomain>.user.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://<your_app_subdomain>.user.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("<your_app_subdomain>.user.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"))