Node.js
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY, DOMAIN, CURRENT_SELECTOR, NEW_SELECTOR } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
if (!DOMAIN) throw new Error("Set DOMAIN (the sending domain, e.g. example.com)");
if (!CURRENT_SELECTOR) throw new Error("Set CURRENT_SELECTOR (the active key to rotate out)");
if (!NEW_SELECTOR) throw new Error("Set NEW_SELECTOR (the selector for the new active key)");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.domains.dkim.rotate(DOMAIN, CURRENT_SELECTOR, {
newKey: { selector: NEW_SELECTOR },
});
if (error) {
console.error("Rotate DKIM key 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")
domain = os.environ.get("DOMAIN")
current_selector = os.environ.get("CURRENT_SELECTOR")
new_selector = os.environ.get("NEW_SELECTOR")
if not domain:
sys.exit("Set DOMAIN (the sending domain, e.g. example.com)")
if not current_selector:
sys.exit("Set CURRENT_SELECTOR (the active key to rotate out)")
if not new_selector:
sys.exit("Set NEW_SELECTOR (the selector for the new active key)")
response = mailchannels.Dkim.rotate(
domain,
current_selector,
new_selector=new_selector,
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$domain = getenv('DOMAIN') or exit("Error: DOMAIN is not set\n");
$current_selector = getenv('CURRENT_SELECTOR') or exit("Error: CURRENT_SELECTOR is not set\n");
$new_selector = getenv('NEW_SELECTOR') or exit("Error: NEW_SELECTOR is not set\n");
$client = new Client(apiKey: $api_key);
$response = $client->dkim->rotate($domain, $current_selector, $new_selector);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/domains/{domain}/dkim-keys/{selector}/rotate \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"new_key": {
"selector": "<string>"
}
}
'{
"new_key": {
"algorithm": "<string>",
"domain": "<string>",
"public_key": "<string>",
"selector": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"dkim_dns_records": [
{
"name": "<string>",
"type": "TXT",
"value": "<string>"
}
],
"gracePeriodExpiresAt": "2023-11-07T05:31:56Z",
"key_length": 123,
"retiresAt": "2023-11-07T05:31:56Z",
"status_modified_at": "2023-11-07T05:31:56Z"
},
"rotated_key": {
"algorithm": "<string>",
"domain": "<string>",
"public_key": "<string>",
"selector": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"dkim_dns_records": [
{
"name": "<string>",
"type": "TXT",
"value": "<string>"
}
],
"gracePeriodExpiresAt": "2023-11-07T05:31:56Z",
"key_length": 123,
"retiresAt": "2023-11-07T05:31:56Z",
"status_modified_at": "2023-11-07T05:31:56Z"
}
}{
"errors": [
"<string>"
]
}Rotate DKIM Key Pair
Rotate an active DKIM key pair. Mark the original key as ‘rotated’, and create a new key pair with the required new key selector, reusing the same algorithm and key length. The rotated key remains valid for signing for a 3-day grace period, and is automatically changed to ‘retired’ 2 weeks after rotation. Publish the new key to its DNS TXT record before rotated key expires for signing as emails sent with an unpublished key will fail DKIM validation by receiving providers. After the grace period, only the new key is valid for signing if published.
POST
/
domains
/
{domain}
/
dkim-keys
/
{selector}
/
rotate
Node.js
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY, DOMAIN, CURRENT_SELECTOR, NEW_SELECTOR } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
if (!DOMAIN) throw new Error("Set DOMAIN (the sending domain, e.g. example.com)");
if (!CURRENT_SELECTOR) throw new Error("Set CURRENT_SELECTOR (the active key to rotate out)");
if (!NEW_SELECTOR) throw new Error("Set NEW_SELECTOR (the selector for the new active key)");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.domains.dkim.rotate(DOMAIN, CURRENT_SELECTOR, {
newKey: { selector: NEW_SELECTOR },
});
if (error) {
console.error("Rotate DKIM key 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")
domain = os.environ.get("DOMAIN")
current_selector = os.environ.get("CURRENT_SELECTOR")
new_selector = os.environ.get("NEW_SELECTOR")
if not domain:
sys.exit("Set DOMAIN (the sending domain, e.g. example.com)")
if not current_selector:
sys.exit("Set CURRENT_SELECTOR (the active key to rotate out)")
if not new_selector:
sys.exit("Set NEW_SELECTOR (the selector for the new active key)")
response = mailchannels.Dkim.rotate(
domain,
current_selector,
new_selector=new_selector,
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$domain = getenv('DOMAIN') or exit("Error: DOMAIN is not set\n");
$current_selector = getenv('CURRENT_SELECTOR') or exit("Error: CURRENT_SELECTOR is not set\n");
$new_selector = getenv('NEW_SELECTOR') or exit("Error: NEW_SELECTOR is not set\n");
$client = new Client(apiKey: $api_key);
$response = $client->dkim->rotate($domain, $current_selector, $new_selector);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/domains/{domain}/dkim-keys/{selector}/rotate \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"new_key": {
"selector": "<string>"
}
}
'{
"new_key": {
"algorithm": "<string>",
"domain": "<string>",
"public_key": "<string>",
"selector": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"dkim_dns_records": [
{
"name": "<string>",
"type": "TXT",
"value": "<string>"
}
],
"gracePeriodExpiresAt": "2023-11-07T05:31:56Z",
"key_length": 123,
"retiresAt": "2023-11-07T05:31:56Z",
"status_modified_at": "2023-11-07T05:31:56Z"
},
"rotated_key": {
"algorithm": "<string>",
"domain": "<string>",
"public_key": "<string>",
"selector": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"dkim_dns_records": [
{
"name": "<string>",
"type": "TXT",
"value": "<string>"
}
],
"gracePeriodExpiresAt": "2023-11-07T05:31:56Z",
"key_length": 123,
"retiresAt": "2023-11-07T05:31:56Z",
"status_modified_at": "2023-11-07T05:31:56Z"
}
}{
"errors": [
"<string>"
]
}Headers
Body
application/json
Show child attributes
Show child attributes
Was this page helpful?
⌘I

