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!
/emails/send-custom-domain/
If you want to use existing email campaign, in the body of your request pass your email campaign id as a value. Remember that your email campaign has to be created as a simple type and it's still active.
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. Email campaign ID is returned as a value.
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"))