import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY, DOMAIN, 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 (!SELECTOR) throw new Error("Set SELECTOR (e.g. mc1)");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.domains.dkim.create(DOMAIN, {
selector: SELECTOR,
algorithm: "rsa",
length: 2048,
});
if (error) {
console.error("Create 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")
selector = os.environ.get("SELECTOR")
if not domain:
sys.exit("Set DOMAIN (the sending domain, e.g. example.com)")
if not selector:
sys.exit("Set SELECTOR (e.g. mc1)")
# Create a MailChannels-managed DKIM key pair. The response includes the
# public key and the DNS TXT record to publish.
response = mailchannels.Dkim.create(
domain,
selector=selector,
algorithm="rsa",
key_length=2048,
)
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");
$selector = getenv('SELECTOR') or exit("Error: SELECTOR is not set\n");
$client = new Client(apiKey: $api_key);
// Create a MailChannels-managed DKIM key pair. The response includes the
// public key and the DNS TXT record to publish.
$response = $client->dkim->create(
domain: $domain,
selector: $selector,
algorithm: 'rsa',
keyLength: 2048,
);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/domains/{domain}/dkim-keys \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"selector": "<string>",
"algorithm": "rsa",
"key_length": 2048
}
'{
"algorithm": "<string>",
"domain": "<string>",
"public_key": "<string>",
"selector": "<string>",
"status": "active",
"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>"
]
}Create DKIM Key Pair
Create a DKIM key pair for a specified domain and selector using the specified algorithm and key length, for the current customer.
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY, DOMAIN, 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 (!SELECTOR) throw new Error("Set SELECTOR (e.g. mc1)");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.domains.dkim.create(DOMAIN, {
selector: SELECTOR,
algorithm: "rsa",
length: 2048,
});
if (error) {
console.error("Create 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")
selector = os.environ.get("SELECTOR")
if not domain:
sys.exit("Set DOMAIN (the sending domain, e.g. example.com)")
if not selector:
sys.exit("Set SELECTOR (e.g. mc1)")
# Create a MailChannels-managed DKIM key pair. The response includes the
# public key and the DNS TXT record to publish.
response = mailchannels.Dkim.create(
domain,
selector=selector,
algorithm="rsa",
key_length=2048,
)
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");
$selector = getenv('SELECTOR') or exit("Error: SELECTOR is not set\n");
$client = new Client(apiKey: $api_key);
// Create a MailChannels-managed DKIM key pair. The response includes the
// public key and the DNS TXT record to publish.
$response = $client->dkim->create(
domain: $domain,
selector: $selector,
algorithm: 'rsa',
keyLength: 2048,
);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/domains/{domain}/dkim-keys \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"selector": "<string>",
"algorithm": "rsa",
"key_length": 2048
}
'{
"algorithm": "<string>",
"domain": "<string>",
"public_key": "<string>",
"selector": "<string>",
"status": "active",
"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
Path Parameters
Body
Selector for the new key pair
1 - 63Algorithm used for the new key pair Currently, only RSA is supported.
rsa Key length in bits. For RSA, must be a multiple of 1024. Common values: 1024 or 2048. Defaults to 2048 bits.
1024 <= x <= 4096Response
Key pair created successfully
Algorithm used for the key pair
Domain associated with the key pair
Selector assigned to the key pair
active, retired, revoked, rotated Timestamp when the key pair was created
Suggested DNS records for the DKIM key
Suggested DNS record for the DKIM key
Show child attributes
Show child attributes
UTC timestamp after which you can no longer use the rotated key for signing
Key length in bits
UTC timestamp when a rotated key pair is retired
Timestamp when the key was last modified
Was this page helpful?

