Emails
Send Email with Template
Send an email using a pre-configured template with dynamic merge fields.
POST
/
v1
/
email
/
template
Send Email with Template
curl --request POST \
--url https://api.unosend.co/v1/email/template \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"template_key": "<string>",
"from": {
"from.address": "<string>",
"from.name": "<string>"
},
"to": [
{
"email_address.address": "<string>",
"email_address.name": "<string>"
}
],
"merge_info": {},
"reply_to": {},
"cc": [
{}
],
"bcc": [
{}
]
}
'import requests
url = "https://api.unosend.co/v1/email/template"
payload = {
"template_key": "<string>",
"from": {
"from.address": "<string>",
"from.name": "<string>"
},
"to": [
{
"email_address.address": "<string>",
"email_address.name": "<string>"
}
],
"merge_info": {},
"reply_to": {},
"cc": [{}],
"bcc": [{}]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
template_key: '<string>',
from: {'from.address': '<string>', 'from.name': '<string>'},
to: [{'email_address.address': '<string>', 'email_address.name': '<string>'}],
merge_info: {},
reply_to: {},
cc: [{}],
bcc: [{}]
})
};
fetch('https://api.unosend.co/v1/email/template', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.unosend.co/v1/email/template",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'template_key' => '<string>',
'from' => [
'from.address' => '<string>',
'from.name' => '<string>'
],
'to' => [
[
'email_address.address' => '<string>',
'email_address.name' => '<string>'
]
],
'merge_info' => [
],
'reply_to' => [
],
'cc' => [
[
]
],
'bcc' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.unosend.co/v1/email/template"
payload := strings.NewReader("{\n \"template_key\": \"<string>\",\n \"from\": {\n \"from.address\": \"<string>\",\n \"from.name\": \"<string>\"\n },\n \"to\": [\n {\n \"email_address.address\": \"<string>\",\n \"email_address.name\": \"<string>\"\n }\n ],\n \"merge_info\": {},\n \"reply_to\": {},\n \"cc\": [\n {}\n ],\n \"bcc\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.unosend.co/v1/email/template")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"template_key\": \"<string>\",\n \"from\": {\n \"from.address\": \"<string>\",\n \"from.name\": \"<string>\"\n },\n \"to\": [\n {\n \"email_address.address\": \"<string>\",\n \"email_address.name\": \"<string>\"\n }\n ],\n \"merge_info\": {},\n \"reply_to\": {},\n \"cc\": [\n {}\n ],\n \"bcc\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.unosend.co/v1/email/template")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"template_key\": \"<string>\",\n \"from\": {\n \"from.address\": \"<string>\",\n \"from.name\": \"<string>\"\n },\n \"to\": [\n {\n \"email_address.address\": \"<string>\",\n \"email_address.name\": \"<string>\"\n }\n ],\n \"merge_info\": {},\n \"reply_to\": {},\n \"cc\": [\n {}\n ],\n \"bcc\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_bodystring
required
The unique key of the template to use.
object
required
array
required
object
Key-value pairs for template variable substitution. Example:
{"first_name": "John", "order_id": "12345"}.object
Reply-to address with
address and optional name.array
CC recipients. Same structure as
to.array
BCC recipients. Same structure as
to.Request
curl -X POST https://api.unosend.co/v1/email/template \
-H "Authorization: Bearer un_xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"template_key": "welcome-email",
"from": {
"address": "hello@yourdomain.com",
"name": "Your App"
},
"to": [
{
"email_address": {
"address": "user@example.com",
"name": "John Doe"
}
}
],
"merge_info": {
"first_name": "John",
"activation_link": "https://yourapp.com/activate/abc123"
}
}'
await fetch('https://api.unosend.co/v1/email/template', {
method: 'POST',
headers: {
'Authorization': 'Bearer un_xxxxxxxxxx',
'Content-Type': 'application/json'
},
body: JSON.stringify({
template_key: 'welcome-email',
from: { address: 'hello@yourdomain.com', name: 'Your App' },
to: [{ email_address: { address: 'user@example.com', name: 'John Doe' } }],
merge_info: { first_name: 'John', activation_link: 'https://yourapp.com/activate/abc123' }
})
});
import requests
requests.post('https://api.unosend.co/v1/email/template',
headers={'Authorization': 'Bearer un_xxxxxxxxxx'},
json={
'template_key': 'welcome-email',
'from': {'address': 'hello@yourdomain.com', 'name': 'Your App'},
'to': [{'email_address': {'address': 'user@example.com', 'name': 'John Doe'}}],
'merge_info': {'first_name': 'John', 'activation_link': 'https://yourapp.com/activate/abc123'}
}
)
Response
200
{
"message": "OK",
"request_id": "req_abc123def456",
"data": {
"message_id": "msg_550e8400e29b41d4"
}
}
Template variables use the
{{variable_name}} syntax. Make sure all required variables in the template are provided in merge_info.⌘I
Send Email with Template
curl --request POST \
--url https://api.unosend.co/v1/email/template \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"template_key": "<string>",
"from": {
"from.address": "<string>",
"from.name": "<string>"
},
"to": [
{
"email_address.address": "<string>",
"email_address.name": "<string>"
}
],
"merge_info": {},
"reply_to": {},
"cc": [
{}
],
"bcc": [
{}
]
}
'import requests
url = "https://api.unosend.co/v1/email/template"
payload = {
"template_key": "<string>",
"from": {
"from.address": "<string>",
"from.name": "<string>"
},
"to": [
{
"email_address.address": "<string>",
"email_address.name": "<string>"
}
],
"merge_info": {},
"reply_to": {},
"cc": [{}],
"bcc": [{}]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
template_key: '<string>',
from: {'from.address': '<string>', 'from.name': '<string>'},
to: [{'email_address.address': '<string>', 'email_address.name': '<string>'}],
merge_info: {},
reply_to: {},
cc: [{}],
bcc: [{}]
})
};
fetch('https://api.unosend.co/v1/email/template', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.unosend.co/v1/email/template",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'template_key' => '<string>',
'from' => [
'from.address' => '<string>',
'from.name' => '<string>'
],
'to' => [
[
'email_address.address' => '<string>',
'email_address.name' => '<string>'
]
],
'merge_info' => [
],
'reply_to' => [
],
'cc' => [
[
]
],
'bcc' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.unosend.co/v1/email/template"
payload := strings.NewReader("{\n \"template_key\": \"<string>\",\n \"from\": {\n \"from.address\": \"<string>\",\n \"from.name\": \"<string>\"\n },\n \"to\": [\n {\n \"email_address.address\": \"<string>\",\n \"email_address.name\": \"<string>\"\n }\n ],\n \"merge_info\": {},\n \"reply_to\": {},\n \"cc\": [\n {}\n ],\n \"bcc\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.unosend.co/v1/email/template")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"template_key\": \"<string>\",\n \"from\": {\n \"from.address\": \"<string>\",\n \"from.name\": \"<string>\"\n },\n \"to\": [\n {\n \"email_address.address\": \"<string>\",\n \"email_address.name\": \"<string>\"\n }\n ],\n \"merge_info\": {},\n \"reply_to\": {},\n \"cc\": [\n {}\n ],\n \"bcc\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.unosend.co/v1/email/template")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"template_key\": \"<string>\",\n \"from\": {\n \"from.address\": \"<string>\",\n \"from.name\": \"<string>\"\n },\n \"to\": [\n {\n \"email_address.address\": \"<string>\",\n \"email_address.name\": \"<string>\"\n }\n ],\n \"merge_info\": {},\n \"reply_to\": {},\n \"cc\": [\n {}\n ],\n \"bcc\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body