Send email messages with custom domain
This endpoint allows you to send email messages using your custom domain settings. You need a custom domain settings ID (which you can get from Email settings) and optionally a custom sender ID (from Sender settings).
HTML is allowed within email message content. For example, you can set the content as:
Hi <b>user</b>, enjoy our product!
The email message will be displayed as:
Hi user, enjoy our product!
Attribute
Optional unless marked required
- api_email_settings/campaign
- The unique identifier of your custom domain settings or campaign automatically generated by User.
- author
- The unique identifier of an email author (string) or author ID (integer).
- content
- The content of your email message (HTML allowed).
- custom_sender
- The unique identifier of your custom sender (optional).
- receivers
- A comma-separated list of user IDs.
- subject
- The subject line for your email message.
- template
- The unique identifier of the email template.
If you want to use an existing email campaign, pass your email campaign ID as the value in the request body. Note that your email campaign must be active.
The author parameter determines who appears as the sender of this email - it can be the owner or any agent of the app.
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/emails/send-custom-domain/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"author": 2,
"receivers": 12345,
"subject": "Your weekly summary",
"content": "<p>Here is what happened in your account this week.</p>",
"template": 165
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/emails/send-custom-domain/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
author: 2,
receivers: 12345,
subject: "Your weekly summary",
content: "<p>Here is what happened in your account this week.</p>",
template: 165,
}),
},
);
const data = await response.json();
console.log(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/emails/send-custom-domain/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Token <your_64_char_api_key>",
"Accept: */*; version=2",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"author" => 2,
"receivers" => 12345,
"subject" => "Your weekly summary",
"content" => "<p>Here is what happened in your account this week.</p>",
"template" => 165,
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/emails/send-custom-domain/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"author": 2,
"receivers": 12345,
"subject": "Your weekly summary",
"content": "<p>Here is what happened in your account this week.</p>",
"template": 165,
},
)
print(response.json())
Response examples
- 201 Created
- 400 Bad Request
{
"campaign": 880
}
{"subject": ["This field is required."],"content": ["This field is required."],"receivers": ["This field is required."],"author": ["This field is required."]}This response indicates that the email has been sent successfully. The returned value is the email campaign ID that was created for this send operation.
Response fields
Fields returned in the 201 Created response body.
- campaign
- ID of the campaign the email belongs to.
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.