import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY, TRACKING_NAME, TRACKING_HOSTNAME } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
if (!TRACKING_NAME) throw new Error("Set TRACKING_NAME (the label used to select this domain at send time)");
if (!TRACKING_HOSTNAME) throw new Error("Set TRACKING_HOSTNAME (e.g. click.example.com)");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
// Register a branded hostname for click tracking, selected at send time by name.
const { data, error } = await mailchannels.domains.customTracking.create(TRACKING_NAME, TRACKING_HOSTNAME, "click");
if (error) {
console.error("Register custom tracking domain failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
name = os.environ.get("TRACKING_NAME")
hostname = os.environ.get("TRACKING_HOSTNAME")
if not name:
sys.exit("Set TRACKING_NAME (the label used to select this domain at send time)")
if not hostname:
sys.exit("Set TRACKING_HOSTNAME (e.g. click.example.com)")
# Register a branded hostname for click tracking, selected at send time by name.
response = mailchannels.CustomTrackingDomains.create(name=name, hostname=hostname, scope="click")
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
use MailChannels\Enum\CustomTrackingScope;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$name = getenv('TRACKING_NAME') or exit("Error: TRACKING_NAME is not set\n");
$hostname = getenv('TRACKING_HOSTNAME') or exit("Error: TRACKING_HOSTNAME is not set\n");
$client = new Client(apiKey: $api_key);
// Register a branded hostname for click tracking, selected at send time by name.
$response = $client->customTrackingDomains->create(
name: $name,
hostname: $hostname,
scope: CustomTrackingScope::Click,
);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/custom-tracking-domains \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"hostname": "<string>",
"name": "<string>"
}
'{
"created_at": "2023-11-07T05:31:56Z",
"hostname": "<string>",
"name": "<string>",
"scope": "click",
"status": "active"
}{
"instructions": "<string>",
"token": "550e8400-e29b-41d4-a716-446655440000",
"txt_record_name": "_mailchannels-verify.click.example.com",
"txt_record_value": "550e8400-e29b-41d4-a716-446655440000"
}{
"errors": [
"<string>"
]
}{
"instructions": "<string>",
"token": "550e8400-e29b-41d4-a716-446655440000",
"txt_record_name": "_mailchannels-verify.click.example.com",
"txt_record_value": "550e8400-e29b-41d4-a716-446655440000"
}Register Custom Tracking Domain
Register a custom branded domain for click tracking, open tracking, or unsubscribe handling.
By default, MailChannels uses shared domains for these links. Using a custom domain improves
brand consistency by replacing shared domains with your own (e.g., click.example.com).
Once registered, select the domain at send time using its name.
Before registration completes, two DNS records must be in place:
- A TXT record at
_mailchannels-verify.<hostname>containing the verification token (returned in the 202 response). - A CNAME record at
<hostname>pointing tolinks.mailchannels.net.
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY, TRACKING_NAME, TRACKING_HOSTNAME } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
if (!TRACKING_NAME) throw new Error("Set TRACKING_NAME (the label used to select this domain at send time)");
if (!TRACKING_HOSTNAME) throw new Error("Set TRACKING_HOSTNAME (e.g. click.example.com)");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
// Register a branded hostname for click tracking, selected at send time by name.
const { data, error } = await mailchannels.domains.customTracking.create(TRACKING_NAME, TRACKING_HOSTNAME, "click");
if (error) {
console.error("Register custom tracking domain failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
name = os.environ.get("TRACKING_NAME")
hostname = os.environ.get("TRACKING_HOSTNAME")
if not name:
sys.exit("Set TRACKING_NAME (the label used to select this domain at send time)")
if not hostname:
sys.exit("Set TRACKING_HOSTNAME (e.g. click.example.com)")
# Register a branded hostname for click tracking, selected at send time by name.
response = mailchannels.CustomTrackingDomains.create(name=name, hostname=hostname, scope="click")
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
use MailChannels\Enum\CustomTrackingScope;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$name = getenv('TRACKING_NAME') or exit("Error: TRACKING_NAME is not set\n");
$hostname = getenv('TRACKING_HOSTNAME') or exit("Error: TRACKING_HOSTNAME is not set\n");
$client = new Client(apiKey: $api_key);
// Register a branded hostname for click tracking, selected at send time by name.
$response = $client->customTrackingDomains->create(
name: $name,
hostname: $hostname,
scope: CustomTrackingScope::Click,
);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/custom-tracking-domains \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"hostname": "<string>",
"name": "<string>"
}
'{
"created_at": "2023-11-07T05:31:56Z",
"hostname": "<string>",
"name": "<string>",
"scope": "click",
"status": "active"
}{
"instructions": "<string>",
"token": "550e8400-e29b-41d4-a716-446655440000",
"txt_record_name": "_mailchannels-verify.click.example.com",
"txt_record_value": "550e8400-e29b-41d4-a716-446655440000"
}{
"errors": [
"<string>"
]
}{
"instructions": "<string>",
"token": "550e8400-e29b-41d4-a716-446655440000",
"txt_record_name": "_mailchannels-verify.click.example.com",
"txt_record_value": "550e8400-e29b-41d4-a716-446655440000"
}Headers
Body
The hostname to register as a custom tracking domain (e.g., click.example.com).
The hostname must have a CNAME record pointing to links.mailchannels.net.
A unique label used to select this domain at message send time
64^[a-z0-9-]+$The event type this domain handles
click, open, unsubscribe Response
Domain verified and registered
ISO 8601 timestamp when the domain was registered
The registered domain hostname
The label for this custom tracking domain
The event type this domain handles
click, open, unsubscribe Current status of the custom tracking domain
active, disabled Was this page helpful?

