Send an email using your custom domain


Email messages using API

This endpoint allows you to send email messages using your custom settings.
All you need is custom domain settings id, and optionally custom sender id.

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-custom-domain/

Data
Type
Description
api_email_settings
integer
ID of your API Email Settings you want to use
custom_sender (optional)
integer
ID of your Custom Sender
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 '{
    "api_email_settings": "1",
    "custom_sender": "1",
    "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-custom-domain/"

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-custom-domain/",
  "method": "POST",
  "headers": {
    "authorization": "Token <your_64_char_api_key>",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "{\n    \"api_email_settings\": \"1\",\n    \"custom_sender\": \"1\",\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({
  "api_email_settings": "1",
  "custom_sender": "1",
  "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-custom-domain/");
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-custom-domain/',
  headers:
   { 'content-type': 'application/json',
     authorization: 'Token <your_64_char_api_key>' },
  body:
   { api_email_settings: 1,
     custom_sender: 1,
     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-custom-domain/",
  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    \"api_email_settings\": \"1\",\n    \"custom_sender\": \"1\",\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-custom-domain/"

payload = "{\n    \"api_email_settings\": \"1\",\n    \"custom_sender\": \"1\",\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    \"api_email_settings\": \"1\",\n    \"custom_sender\": \"1\",\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-custom-domain/", payload, headers)

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

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