Domains¶
The domains endpoint is available at:
v4/domains
The domains API allows you to create, access, and validate domains programmatically.
GET /domains
Returns a list of domains under your account in JSON. See examples below.
Parameter | Description |
---|---|
authority | Filter the list by a given DKIM authority name |
state | Filter the list by a given state. Can be active , unverified or disabled |
limit | Maximum number of records to return. (100 by default) |
skip | Number of records to skip. (0 by default) |
GET /domains/<domain>
Returns a single domain, including credentials and DNS records. See examples below.
PUT /domains/<domain>/verify
Places the domain in an unverified state and triggers the verification process. Returns a single domain, including credentials and DNS records. If the domain is successfully verified the domain’s state will be ‘active’. For more information on verifying domains, visit the Mailgun User Manual.
POST /domains
Create a new domain. See examples below.
Parameter | Description |
---|---|
name | Name of the domain (ex. domain.com) |
smtp_password | Password for SMTP authentication |
spam_action |
If If If The default is |
wildcard |
Determines whether the domain will accept email for sub-domains when sending messages. The default is |
force_dkim_authority |
If set to If set to The default is |
dkim_key_size |
Set the length of your domain’s generated DKIM key The default is |
ips | An optional, comma-separated list of IP addresses to be assigned
to this domain. If not specified, all dedicated IP addresses on
the account will be assigned. If the request cannot be fulfilled
(e.g. a requested IP is not assigned to the account, etc), a
400 will be returned. |
pool_id | The id of the IP Pool that you wish to assign to the domain. The pool must contain at least 1 IP. (Note: IP Pools are only available on certain plans; see http://mailgun.com/pricing) |
web_scheme |
Set your open, click and unsubscribe URLs to use http or https The default is |
PUT /domains/<domain>
Update domain parameters. See examples below.
Parameter | Type | Description |
---|---|---|
spam_action | String |
If If If The default is |
web_scheme | String |
Set your open, click and unsubscribe URLs to use http or https The default is |
wildcard | Boolean |
Determines whether the domain will accept email for sub-domains when sending messages. The default is |
DELETE /domains/<domain>
Delete a domain from your account.
POST /domains/<domain>/credentials
Creates a new set of SMTP credentials for the defined domain.
Parameter | Description |
---|---|
login | The user name, for example bob.bar |
password | A password for the SMTP credentials. (Length Min 5, Max 32) |
PUT /domains/<domain>/credentials/<login>
Updates the specified SMTP credentials. Currently only the password can be changed.
Parameter | Description |
---|---|
password | A password for the SMTP credentials. (Length Min 5, Max 32) |
DELETE /domains/<domain>/credentials/<login>
Deletes the defined SMTP credentials.
Note
Mailgun imposes a rate limit for the Domains API endpoint. Users may issue no more than 300 requests per minute, per account. See the resultant rate limit response below.
GET /domains/<domain>/connection
Returns delivery connection settings for the defined domain.
PUT /domains/<domain>/connection
Updates the specified delivery connection settings for the defined domain.
Parameter | Description |
---|---|
require_tls | true or false If set to true, this requires the message only be sent over a TLS connection. If a TLS connection can not be established, Mailgun will not deliver the message. If set to false, Mailgun will still try and upgrade the connection, but if Mailgun cannot, the message will be delivered over a plaintext SMTP connection. The default is false. |
skip_verification | true or false If set to true, the certificate and hostname will not be verified when trying to establish a TLS connection and Mailgun will accept any certificate during delivery. If set to false, Mailgun will verify the certificate and hostname. If either one can not be verified, a TLS connection will not be established. The default is false. |
GET /domains/<domain>/tracking
Returns tracking settings for a domain.
PUT /domains/<domain>/tracking/open
Updates the open tracking settings for a domain.
Parameter | Description |
---|---|
active |
If set to yes, a tracking pixel will be inserted below your HTML content. |
place_at_the_top |
If set to yes, tracking pixel will be moved to top of your HTML content. |
PUT /domains/<domain>/tracking/click
Updates the click tracking settings for a domain.
Parameter | Description |
---|---|
active |
If set to yes, links will be overwritten and pointed to our servers so we can track clicks. |
PUT /domains/<domain>/tracking/unsubscribe
Updates unsubscribe tracking settings for a domain.
Parameter | Description |
---|---|
active | true or false. |
html_footer | Custom HTML version of unsubscribe footer. |
text_footer | Custom text version of unsubscribe footer. Mailgun can automatically provide an unsubscribe footer in each email you send and also provides you with several unsubscribe variables. You can customize your unsubscribe footer by editing the settings in the Control Panel. See Open and Click Bot Detection for more details. |
PUT /domains/<domain>/dkim_authority
Change the DKIM authority for a domain.
Parameter | Description |
---|---|
self | true or false Change the DKIM authority for a domain. If set to true, the domain will be the DKIM authority for itself even if the root domain is registered on the same mailgun account If set to false, the domain will have the same DKIM authority as the root domain registered on the same mailgun account |
Note
Use with caution: Do not forget to change the corresponding DNS record. It can take 24-48 hours for DNS changes to propagate. Changing the DKIM authority of an active domain affects its current deliverability.
Update the DKIM selector for a domains
PUT /domains/<domain>/dkim_selector
Parameter | Description |
---|---|
dkim_selector | change the DKIM selector for a domain. |
Update the CNAME used for tracking opens and clicks
PUT /domains/<domain>/web_prefix
Parameter | Description |
---|---|
web_prefix | change the tracking CNAME for a domain. |
Lists the domain keys for a specified signing domain / authority
GET /v4/domains/{authority_name}/keys
Parameter | Description |
---|---|
authority_name (string) | The domain authority name you want to list the domain keys for. Must be a valid domain |
Activate a domain key for a specified authority and selector. Note: dns records must be valid for a domain key to be activated
PUT /v4/domains/{authority_name}/keys/{selector}/activate
Parameter | Description |
---|---|
authority_name (string) | The domain authority name you want to activate. Must be a valid domain |
selector (string) | The selector you want to activate for the domain key. Must be a valid dot atom |
Deactivate a domain key for a specified authority and selector
PUT /v4/domains/{authority_name}/keys/{selector}/deactivate
Parameter | Description |
---|---|
authority_name (string) | The domain authority name you want to deactivate. Must be a valid domain |
selector (string) | The selector you want to deactivate for the domain key. Must be a valid dot atom |
Create a domain key. Note that once private keys are created or imported they are never exported. Alternatively, you can import an existing PEM file containing a RSA private key in PKCS #1, ASn.1 DER format. Note, When importing an existing key it must match the public key available via DNS at the time the api call to create the domain key is made. Additionally, an authority is allowed a maximum of 3 domain keys.
POST /v1/dkim/keys
List domain keys. Optionally filter by signing domain or selector.
GET /v1/dkim/keys
Parameter | Description |
---|---|
page (string) (required) | Encoded paging information, provided via ‘next’, ‘previous’ links |
limit (int) (required) | Limits the number of items returned in a request |
signing_domain (string) | Filter by signing domain |
selector (string) | Filter by selector |
Delete a domain key. Domain keys are not recoverable after deletion so use with care!
DELETE /v1/dkim/keys
Parameter | Description |
---|---|
signing_domain (string) (required) | Signing domain |
selector (string) (required) | Selector |
Examples¶
Get a list of all domains.
curl -s --user 'api:YOUR_API_KEY' -G \
https://api.mailgun.net/v3/domains \
-d skip=0 \
-d limit=3
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.enums.DomainState;
import com.mailgun.model.domains.DomainListResponse;
import com.mailgun.model.domains.DomainsParametersFilter;
// ...
public DomainListResponse getDomains() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
DomainsParametersFilter filter = DomainsParametersFilter.builder()
.skip(0)
.limit(3)
.state(DomainState.ACTIVE)
.build();
return mailgunDomainsApi.getDomainsList(filter);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
# Issue the call to the client.
$result = $mgClient->domains()->index();
def get_domains():
return requests.get(
"https://api.mailgun.net/v3/domains",
auth=("api", "YOUR_API_KEY"),
params={"skip": 0,
"limit": 3})
def get_domains
RestClient.get "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains", :params => {
:skip => 0,
:limit => 3
}
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class GetDomainsChunk
{
public static void Main (string[] args)
{
Console.WriteLine (GetDomains ().Content.ToString ());
}
public static IRestResponse GetDomains ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "domains";
request.AddParameter ("skip", 0);
request.AddParameter ("limit", 3);
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func ListDomains(domain, apiKey string) ([]mailgun.Domain, error) {
mg := mailgun.NewMailgun(domain, apiKey)
it := mg.ListDomains(nil)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
var page, result []mailgun.Domain
for it.Next(ctx, &page) {
result = append(result, page...)
}
if it.Err() != nil {
return nil, it.Err()
}
return result, nil
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const domainsList = await client.domains.list();
console.log('domainsList', domainsList);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"items": [
{
"created_at": "Mon, 30 Sep 2019 16:20:48 GMT",
"id": "55a55f40803267158aa113e8",
"is_disabled": false,
"name": "samples.mailgun.org",
"require_tls": false,
"skip_verification": false,
"smtp_login": "postmaster@samples.mailgun.org",
"spam_action": "disabled",
"state": "active",
"type": "sandbox",
"web_prefix": "email",
"web_scheme": "http",
"wildcard": false
}
],
"total_count": 1
}
Get a single domain.
curl -s --user 'api:YOUR_API_KEY' -G \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.domains.SingleDomainResponse;
// ...
public SingleDomainResponse getDomain() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
return mailgunDomainsApi.getSingleDomain(YOUR_DOMAIN_NAME);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
# Issue the call to the client.
$result = $mgClient->domains()->show($domain);
def get_domain():
return requests.get(
"https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME",
auth=("api", "YOUR_API_KEY"))
def get_domain
RestClient.get("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME"\
{|response, request, result| response }
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class GetDomainChunk
{
public static void Main (string[] args)
{
Console.WriteLine (GetDomain ().Content.ToString ());
}
public static IRestResponse GetDomain ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "/domains/{domain}";
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func GetDomain(domain, apiKey string) (mailgun.DomainResponse, error) {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.GetDomain(ctx, domain)
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const domain = await client.domains.get(DOMAIN);
console.log('domain', domain);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"domain": {
"created_at": "Tue, 14 Jul 2015 19:13:04 GMT",
"id": "55a55f40803267158aa113e8",
"is_disabled": false,
"name": "samples.mailgun.org",
"require_tls": false,
"skip_verification": false,
"smtp_login": "postmaster@samples.mailgun.org",
"spam_action": "disabled",
"state": "active",
"type": "sandbox",
"web_prefix": "email",
"web_scheme": "http",
"wildcard": false
},
"receiving_dns_records": [
{
"priority": "10",
"record_type": "MX",
"valid": "valid",
"value": "mxa.mailgun.org"
},
{
"priority": "10",
"record_type": "MX",
"valid": "valid",
"value": "mxb.mailgun.org"
}
],
"sending_dns_records": [
{
"record_type": "TXT",
"valid": "valid",
"name": "domain.com",
"value": "v=spf1 include:mailgun.org ~all"
},
{
"record_type": "TXT",
"valid": "valid",
"name": "domain.com",
"value": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUA...."
},
{
"record_type": "CNAME",
"valid": "valid",
"name": "email.domain.com",
"value": "mailgun.org"
}
]
}
Adding a domain.
curl -s --user 'api:YOUR_API_KEY' \
-X POST https://api.mailgun.net/v3/domains \
-F name='YOUR_NEW_DOMAIN_NAME' \
-F smtp_password='supersecretpassword'
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.enums.SpamAction;
import com.mailgun.enums.WebScheme;
import com.mailgun.model.domains.DomainRequest;
import com.mailgun.model.domains.DomainResponse;
import java.util.List;
// ...
public DomainResponse addDomain() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
DomainRequest request = DomainRequest.builder()
.name(YOUR_NEW_DOMAIN_NAME)
.spamAction(SpamAction.BLOCK)
.wildcard(true)
.forceDkimAuthority(false)
.dkimKeySize(1024)
.ips(List.of(IP_1, IP_2))
.webScheme(WebScheme.HTTPS)
.build();
return mailgunDomainsApi.createNewDomain(request);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = 'YOUR_DOMAIN_NAME';
# Issue the call to the client.
$result = $mgClient->domains()->create($domain);
def add_domain():
return requests.post(
"https://api.mailgun.net/v3/domains",
auth=("api", "YOUR_API_KEY"),
data={'name':'YOUR_NEW_DOMAIN_NAME', 'smtp_password':'supersecretpassword'})
def add_domain
RestClient.post("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains",
:name => 'YOUR_NEW_DOMAIN_NAME',
:smtp_password => 'supersecretpassword')
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class AddDomainChunk
{
public static void Main (string[] args)
{
Console.WriteLine (AddDomain ().Content.ToString ());
}
public static IRestResponse AddDomain ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3/");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "domains";
request.AddParameter ("name", "YOUR_NEW_DOMAIN_NAME");
request.AddParameter ("smtp_password", "supersecretpassword");
request.Method = Method.POST;
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func AddDomain(domain, apiKey string) error {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.CreateDomain(ctx, "example.com", &mailgun.CreateDomainOptions{
Password: "super_secret",
SpamAction: mailgun.SpamActionTag,
Wildcard: false,
})
}
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const newDomain = await client.domains.create({
name: "YOUR_NEW_DOMAIN_NAME",
smtp_login: "smtpLogin",
smtp_password: 'supersecret!'
});
console.log('newDomain', newDomain);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"domain": {
"created_at": "Tue, 14 Jul 2015 19:13:04 GMT",
"id": "55a55f40803267158aa113e8",
"is_disabled": false,
"name": "samples.mailgun.org",
"require_tls": false,
"skip_verification": false,
"smtp_login": "postmaster@samples.mailgun.org",
"spam_action": "disabled",
"state": "active",
"type": "sandbox",
"web_prefix": "email",
"web_scheme": "http",
"wildcard": false
},
"message": "Domain has been created",
"receiving_dns_records": [
{
"cached": [],
"priority": "10",
"record_type": "MX",
"valid": "valid",
"value": "mxa.mailgun.org"
},
{
"cached": [],
"priority": "10",
"record_type": "MX",
"valid": "valid",
"value": "mxb.mailgun.org"
}
],
"sending_dns_records": [
{
"cached": [],
"name": "example.com",
"record_type": "TXT",
"valid": "valid",
"value": "v=spf1 include:mailgun.org ~all"
},
{
"cached": [],
"name": "k1._domainkey.example.com",
"record_type": "TXT",
"valid": "valid",
"value": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4G...."
},
{
"cached": [],
"name": "email.example.com",
"record_type": "CNAME",
"valid": "valid",
"value": "mailgun.org"
}
]
}
Deleting a domain.
curl -s --user 'api:YOUR_API_KEY' -X DELETE \
https://api.mailgun.net/v3/domains/example.mailgun.org
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.ResponseWithMessage;
// ...
public ResponseWithMessage deleteDomain() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
return mailgunDomainsApi.deleteDomain(YOUR_DOMAIN_NAME);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = 'YOUR_DOMAIN_NAME';
# Issue the call to the client.
$result = $mgClient->domains()->delete($domain);
def delete_domain():
return requests.delete(
"https://api.mailgun.net/v3/domains/example.mailgun.org",
auth=("api", "YOUR_API_KEY"))
def delete_domain
RestClient.delete "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/example.mailgun.org"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class DeleteDomainChunk
{
public static void Main (string[] args)
{
Console.WriteLine (DeleteDomain ().Content.ToString ());
}
public static IRestResponse DeleteDomain ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "/domains/{name}";
request.AddUrlSegment ("name", "example.mailgun.org");
request.Method = Method.DELETE;
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func DeleteDomain(domain, apiKey string) error {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.DeleteDomain(ctx, "example.com")
}
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const destroyedDomain = await client.domains.destroy('DOMAIN_TO_DELETE');
console.log('destroyedDomain', destroyedDomain);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"message": "Domain has been deleted"
}
Rate Limit Response:
{
"retry-seconds": 60,
}
Listing all SMTP credentials:
curl -s --user 'api:YOUR_API_KEY' -G \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class MGSample {
// ...
public static JsonNode getCredentials() throws UnirestException {
HttpResponse<JsonNode> request = Unirest.get("https://api.mailgun.net/v3/domains/" + YOUR_DOMAIN_NAME + "/credentials")
.basicAuth("api", API_KEY)
.asJson();
return request.getBody();
}
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
# Issue the call to the client.
$result = $mgClient->domains()->credentials($domain);
def get_credentials():
return requests.get(
"https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials",
auth=("api", "YOUR_API_KEY"))
def get_credentials
RestClient.get "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class GetCredentialsChunk
{
public static void Main (string[] args)
{
Console.WriteLine (GetCredentials ().Content.ToString ());
}
public static IRestResponse GetCredentials ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "domains/{domain}/credentials";
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func ListCredentials(domain, apiKey string) ([]mailgun.Credential, error) {
mg := mailgun.NewMailgun(domain, apiKey)
it := mg.ListCredentials(nil)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
var page, result []mailgun.Credential
for it.Next(ctx, &page) {
result = append(result, page...)
}
if it.Err() != nil {
return nil, it.Err()
}
return result, nil
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const domainCredentials = await client.domains.domainCredentials.list(DOMAIN);
console.log('domainCredentials', domainCredentials);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"total_count": 2,
"items": [
{
"size_bytes": 0,
"created_at": "Tue, 27 Sep 2011 20:24:22 GMT",
"mailbox": "user@samples.mailgun.org",
"login": "user@samples.mailgun.org"
},
{
"size_bytes": 0,
"created_at": "Thu, 06 Oct 2011 10:22:36 GMT",
"mailbox": "user@samples.mailgun.org",
"login": "user@samples.mailgun.org"
}
]
}
Creating new SMTP credentials:
curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials \
-F login='alice@YOUR_DOMAIN_NAME' \
-F password='supasecret'
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.ResponseWithMessage;
import com.mailgun.model.domains.DomainCredentials;
// ...
public ResponseWithMessage createCredentials() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
DomainCredentials domainCredentials = DomainCredentials.builder()
.login("alice@YOUR_DOMAIN_NAME.com")
.password( "super_secret_password")
.build();
return mailgunDomainsApi.createNewCredentials(YOUR_DOMAIN_NAME, domainCredentials);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = 'YOUR_DOMAIN_NAME';
$smtpUser = 'bob';
$smtpPass = 'new_password';
# Issue the call to the client.
$result = $mgClient->domains()->createCredential($domain, $smtpUser, $smtpPass);
def create_credentials():
return requests.post(
"https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials",
auth=("api", "YOUR_API_KEY"),
data={"login": "alice@YOUR_DOMAIN_NAME",
"password": "secret"})
def create_credentials
RestClient.post "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials",
:login => "alice@YOUR_DOMAIN_NAME",
:password => "secret"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class CreateCredentialsChunk
{
public static void Main (string[] args)
{
Console.WriteLine (CreateCredentials ().Content.ToString ());
}
public static IRestResponse CreateCredentials ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "domains/{domain}/credentials";
request.AddParameter ("login", "alice@YOUR_DOMAIN_NAME");
request.AddParameter ("password", "secret");
request.Method = Method.POST;
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func CreateCredential(domain, apiKey string) error {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.CreateCredential(ctx, "alice@example.com", "secret")
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const createdCredentials = await client.domains.domainCredentials.create(DOMAIN, {
login: 'alice@YOUR_DOMAIN_NAME',
password: 'secret'
});
console.log('createdCredentials', createdCredentials);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"message": "Created 1 credentials pair(s)"
}
Updating the password for a given credential pair:
curl -s --user 'api:YOUR_API_KEY' -X PUT \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials/alice \
-F password='abc123'
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.ResponseWithMessage;
// ...
public ResponseWithMessage updatePassword() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
return mailgunDomainsApi.updateCredentials(YOUR_DOMAIN_NAME, YOUR_LOGIN, "super_secret_password");
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = 'YOUR_DOMAIN_NAME';
$smtpUser = 'bob';
$smtpPass = 'new_password';
# Issue the call to the client.
$result = $mgClient->domains()->updateCredential($domain, $smtpUser, $smtpPass);
def change_credential_password():
return requests.put(
"https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials/alice",
auth=("api", "YOUR_API_KEY"),
data={"password": "supersecret"})
def change_credential_password
RestClient.put "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials/alice",
:password => "supersecret"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class ChangePwdCredentialsChunk
{
public static void Main (string[] args)
{
Console.WriteLine (ChangeCredentialPassword ().Content.ToString ());
}
public static IRestResponse ChangeCredentialPassword ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "domains/{domain}/credentials/{username}";
request.AddUrlSegment ("username", "alice");
request.AddParameter ("password", "supersecret");
request.Method = Method.PUT;
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func ChangePassword(domain, apiKey string) error {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.ChangeCredentialPassword(ctx, "alice", "super_secret")
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const updatedCredentials = await client.domains.domainCredentials.update(DOMAIN, 'LOGIN_FROM_CREDENTIALS', {
password: 'new_password'
});
console.log('updatedCredentials -------->', updatedCredentials);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"message": "Password changed"
}
Deleting a given credential pair:
curl -s --user 'api:YOUR_API_KEY' -X DELETE \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials/alice
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.ResponseWithMessage;
// ...
public ResponseWithMessage deleteCredentials() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
return mailgunDomainsApi.deleteCredentials(YOUR_DOMAIN_NAME, YOUR_LOGIN);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = 'YOUR_DOMAIN_NAME';
$smtpUser = 'bob';
# Issue the call to the client.
$result = $mgClient->domains()->deleteCredential($domain, $smtpUser);
def delete_credentials():
return requests.delete(
"https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials/alice",
auth=("api", "YOUR_API_KEY"))
def delete_credentials
RestClient.delete "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials/alice"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class DeleteCredentialsChunk
{
public static void Main (string[] args)
{
Console.WriteLine (DeleteCredentials ().Content.ToString ());
}
public static IRestResponse DeleteCredentials ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "domains/{domain}/credentials/{login}";
request.AddUrlSegment ("login", "alice");
request.Method = Method.DELETE;
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func DeleteCredential(domain, apiKey string) error {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.DeleteCredential(ctx, "alice")
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const deletedDomainCredentials = await client.domains.domainCredentials.destroy(DOMAIN, 'alice@YOUR_DOMAIN_NAME');
console.log('deletedDomainCredentials', deletedDomainCredentials);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"message": "Credentials have been deleted",
"spec": "alice@samples.mailgun.org"
}
Listing connection settings:
curl -s --user 'api:YOUR_API_KEY' -G \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/connection
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.domains.DomainConnectionResponse;
// ...
public DomainConnectionResponse getConnections() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
return mailgunDomainsApi.getDomainConnectionSettings(YOUR_DOMAIN_NAME);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
# Issue the call to the client.
$result = $mgClient->domains()->connection($domain);
def get_connection():
return requests.get(
"https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/connection",
auth=("api", "YOUR_API_KEY"))
def get_connection
RestClient.get "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/connection"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class GetConnectionChunk
{
public static void Main (string[] args)
{
Console.WriteLine (GetConnection ().Content.ToString ());
}
public static IRestResponse GetConnection ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "domains/{domain}/connection";
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func GetDomainConnection(domain, apiKey string) (mailgun.DomainConnection, error) {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.GetDomainConnection(ctx, domain)
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const connectionSettings = await client.domains.getConnection(DOMAIN);
console.log('connectionSettings', connectionSettings);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"connection": {
"require_tls": false,
"skip_verification": false
}
Update connection settings:
curl -s --user 'api:YOUR_API_KEY' -X PUT \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/connection
-F require_tls='true' \
-F skip_verification='false'
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.domains.DomainConnectionRequest;
import com.mailgun.model.domains.UpdateDomainConnectionResponse;
// ...
public UpdateDomainConnectionResponse updateConnections() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
DomainConnectionRequest domainConnection = DomainConnectionRequest.builder()
.requireTls(true)
.skipVerification(false)
.build();
return mailgunDomainsApi.updateDomainConnectionSettings(YOUR_DOMAIN_NAME, domainConnection);
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
$require_tls = true;
$skip_verification = false;
# Issue the call to the client.
$result = $mgClient->domains()->updateConnection($domain, $require_tls, $skip_verification);
def update_connection():
return requests.put(
("https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/connection"),
auth=('api', 'YOUR_API_KEY'),
data={'require_tls': True,
'skip_verification': False})
def update_member
RestClient.put("https://api:YOUR_API_KEY" \
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/connection",
:require_tls => true,
:skip_verification => false)
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class UpdateConnectionChunk
{
public static void Main (string[] args)
{
Console.WriteLine (UpdateConnection ().Content.ToString ());
}
public static IRestResponse UpdateConnection ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "domains/YOUR_DOMAIN_NAME/connection";
request.AddParameter ("require_tls", true);
request.AddParameter ("skip_verification", false);
request.Method = Method.PUT;
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func UpdateDomainConnection(domain, apiKey string) error {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.UpdateDomainConnection(ctx, domain, mailgun.DomainConnection{
RequireTLS: true,
SkipVerification: true,
})
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const updatedConnection = await client.domains.updateConnection('DOMAIN', {
require_tls: true,
skip_verification: false
});
console.log('updatedConnection', updatedConnection);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"message": "Domain connection settings have been updated, may take 10 minutes to fully propagate",
"require-tls": true,
"skip-verification": false
}
Get tracking settings for a domain:
curl -s --user 'api:YOUR_API_KEY' -G \
https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/tracking
import com.mailgun.api.v3.MailgunDomainsApi;
import com.mailgun.model.domains.DomainTrackingResponse;
// ...
public DomainTrackingResponse getDomainTracking() {
MailgunDomainsApi mailgunDomainsApi = MailgunClient.config(API_KEY)
.createApi(MailgunDomainsApi.class);
return mailgunDomainsApi.getDomainTrackingSettings(YOUR_DOMAIN_NAME);
}
# Currently, the PHP SDK does not support Mailing List verifications.
# Consider using the following php curl function.
function get_domain_tracking_settings() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:PRIVATE_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/tracking');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
def get_domain_tracking():
return requests.get(
"https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/tracking",
auth=("api", "YOUR_API_KEY"))
def get_domain_tracking
RestClient.get("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/tracking"\
{|response, request, result| response }
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class GetDomainTrackingChunk
{
public static void Main (string[] args)
{
Console.WriteLine (GetDomainTracking ().Content.ToString ());
}
public static IRestResponse GetDomainTracking ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
request.Resource = "/domains/{domain}/tracking";
return client.Execute (request);
}
}
import (
"context"
"github.com/mailgun/mailgun-go/v3"
"time"
)
func GetDomainTracking(domain, apiKey string) (mailgun.DomainTracking, error) {
mg := mailgun.NewMailgun(domain, apiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
return mg.GetDomainTracking(ctx, domain)
}
const DOMAIN = 'YOUR_DOMAIN_NAME';
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
const client = mailgun.client({ username: 'api', key: 'YOUR_API_KEY' || '' });
(async () => {
try {
const tracking = await client.domains.getTracking(DOMAIN);
console.log('tracking', tracking);
} catch (error) {
console.error(error);
}
})();
Sample response:
{
"tracking": {
"click": {
"active": false
},
"open": {
"active": false
},
"unsubscribe": {
"active": false,
"html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
"text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
}
}
}
Lists the domain keys for a specified signing domain / authority
curl -s --user `api:YOUR_API_KEY' -G \
https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class MGSample {
// ...
public static JsonNode listDomainKeys() throws UnirestException {
HttpResponse<JsonNode> request = Unirest.get("https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys")
.basicAuth("api", API_KEY)
.asJson();
return request.getBody();
}
}
function list_domain_keys() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:PRIVATE_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
def list_domain_keys():
return requests.get(
"https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys",
auth=('api', 'YOUR_API_KEY'))
def get_domain_keys
RestClient.get("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys")
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class InboxPlacementTests
{
public static void Main (string[] args)
{
Console.WriteLine (ListDomainKeys ().Content.ToString ());
}
public static IRestResponse ListDomainKeys ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v4");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "domains/AUTHORITY_DOMAIN_NAME/keys";
request.Method = Method.GET;
return client.Execute (request);
}
}
import (
"encoding/json"
"net/http"
)
type ListDomainKeyResp struct {
Items []DomainKey `json:"items"`
}
type DomainKey struct {
SigningDomain string `json:"signing_domain"`
Selector string `json:"selector"`
Record Record `json:"dns_record"`
}
type Record struct {
Active bool `json:"is_active"`
Cached []string `json:"cached"`
Name string `json:"name"`
Type string `json:"record_type"`
Valid string `json:"valid"`
Value string `json:"value"`
}
func ListDomainKeys() (listDomainKeyResp LitDomainKeyResp, err error) {
// creating HTTP request and returning response
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys", nil)
req.SetBasicAuth("api", apiKey)
response, err := client.Do(req)
if err != nil {
return
}
defer response.Body.Close()
// Decode response.
err = json.NewDecoder(response.Body).Decode(&listDomainKeyResp)
return
}
Sample response 200:
{
"items": [
{
"dns_record": {
"cached": [
"cached dns value"
],
"is_active": true,
"name": "s1._domainkey.authority.domain.tld",
"record_type": "TXT",
"valid": "VALID",
"value": "expected dns value"
},
"selector": "s1",
"signing_domain": "authority.domain.tld"
},
{
"dns_record": {
"cached": [
"cached dns value"
],
"is_active": false,
"name": "s2._domainkey.authority.domain.tld",
"record_type": "TXT",
"valid": "UNKNOWN",
"value": "expected dns value"
},
"selector": "s2",
"signing_domain": "authority.domain.tld"
}
]
}
Activate a domain key
curl -s --user `api:YOUR_API_KEY' -X PUT \
https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/activate
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class MGSample {
// ...
public static JsonNode activateDomainKey() throws UnirestException {
HttpResponse<JsonNode> request = Unirest.put("https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/activate")
.basicAuth("api", API_KEY)
.asJson();
return request.getBody();
}
}
function activate_domain_key() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:PRIVATE_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/activate');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
def activate_domain_key():
return requests.put(
"https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/activate",
auth=('api', 'YOUR_API_KEY'))
def activate_domain_key
RestClient.put("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/activate")
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class InboxPlacementTests
{
public static void Main (string[] args)
{
Console.WriteLine (ActivateDomainKey ().Content.ToString ());
}
public static IRestResponse ActivateDomainKey ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v4");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "domains/AUTHORITY_DOMAIN_NAME/keys";
request.Method = Method.PUT;
return client.Execute (request);
}
}
import (
"encoding/json"
"fmt"
"net/http"
)
type ActivateDomainKeyResp struct {
Msg string `json:"message"`
Authority string `json:"authority"`
Selector string `json:"selector"`
Active bool `json:"active"`
}
func ActivateDomainKey() (activateDomainKeyResp ActivateDomainKeyResp, err error) {
authority := "AUTHORITY_DOMAIN_NAME"
selector := "SELECTOR"
client := &http.Client{}
req, _ := http.NewRequest("GET", fmt.Sprintf("https://api.mailgun.net/v4/domains/%s/keys/%s/activate", authority, selector), nil)
req.SetBasicAuth("api", apiKey)
response, err := client.Do(req)
if err != nil {
return
}
defer response.Body.Close()
// Decode response.
err = json.NewDecoder(response.Body).Decode(&activateDomainKeyResp)
return
}
Sample response 200:
{
"active": true,
"authority": "authority.domain.tld",
"message": "domain key activated",
"selector": "selector"
}
Deactivate a domain key
curl -s --user `api:YOUR_API_KEY' -X PUT \
https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/deactivate
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class MGSample {
// ...
public static JsonNode deactivateDomainKey() throws UnirestException {
HttpResponse<JsonNode> request = Unirest.put("https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/deactivate")
.basicAuth("api", API_KEY)
.asJson();
return request.getBody();
}
}
function deactivate_domain_key() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:PRIVATE_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/deactivate');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
def deactivate_domain_key():
return requests.put(
"https://api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/deactivate",
auth=('api', 'YOUR_API_KEY'))
def deactivate_domain_key
RestClient.put("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v4/domains/AUTHORITY_DOMAIN_NAME/keys/SELECTOR/deactivate")
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class InboxPlacementTests
{
public static void Main (string[] args)
{
Console.WriteLine (DeactivateDomainKey ().Content.ToString ());
}
public static IRestResponse DeactivateDomainKey ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v4");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "domains/AUTHORITY_DOMAIN_NAME/keys/deactivate";
request.Method = Method.PUT;
return client.Execute (request);
}
}
import (
"encoding/json"
"fmt"
"net/http"
)
type DeactivateDomainKeyResp struct {
Msg string `json:"message"`
Authority string `json:"authority"`
Selector string `json:"selector"`
Active bool `json:"active"`
}
func DeactivateDomainKey() (deactivateDomainKeyResp DeactivateDomainKeyResp, err error) {
authority := "AUTHORITY_DOMAIN_NAME"
selector := "SELECTOR"
client := &http.Client{}
req, _ := http.NewRequest("GET", fmt.Sprintf("https://api.mailgun.net/v4/domains/%s/keys/%s/deactivate", authority, selector), nil)
req.SetBasicAuth("api", apiKey)
response, err := client.Do(req)
if err != nil {
return
}
defer response.Body.Close()
// Decode response.
err = json.NewDecoder(response.Body).Decode(&activateDomainKeyResp)
return
}
Sample response 200:
{
"active": true,
"authority": "authority.domain.tld",
"message": "domain key deactivated",
"selector": "selector"
}
List all domain keys associated to account
curl -s --user `api:YOUR_API_KEY' -G \
https://api.mailgun.net/v1/dkim/keys
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class MGSample {
// ...
public static JsonNode listDomainKeys() throws UnirestException {
HttpResponse<JsonNode> request = Unirest.get("https://api.mailgun.net/v1/dkim/keys")
.basicAuth("api", API_KEY)
.asJson();
return request.getBody();
}
}
function list_domain_keys() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:PRIVATE_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v1/dkim/keys');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
def list_domain_keys():
return requests.get(
"https://api.mailgun.net/v1/dkim/keys",
auth=('api', 'YOUR_API_KEY'))
def get_domain_keys
RestClient.get("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v1/dkim/keys")
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class InboxPlacementTests
{
public static void Main (string[] args)
{
Console.WriteLine (ListDomainKeys ().Content.ToString ());
}
public static IRestResponse ListDomainKeys ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v1");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "dkim/keeys";
request.Method = Method.GET;
return client.Execute (request);
}
}
import (
"encoding/json"
"net/http"
)
type ListDomainKeyResp struct {
Items []DomainKey `json:"items"`
Page PagingResponse `json:"paging"`
}
type DomainKey struct {
SigningDomain string `json:"signing_domain"`
Selector string `json:"selector"`
Record Record `json:"dns_record"`
Page PagingResponse `json:"paging"`
}
type Record struct {
Active bool `json:"is_active"`
Cached []string `json:"cached"`
Name string `json:"name"`
Type string `json:"record_type"`
Valid string `json:"valid"`
Value string `json:"value"`
}
type PagingResponse struct {
Previous string `json:"previous"`
First string `json:"first"`
Next string `json:"next"`
Last string `json:"last"`
}
func ListDomainKeys() (listDomainKeyResp LitDomainKeyResp, err error) {
// creating HTTP request and returning response
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.mailgun.net/v1/dkim/keys", nil)
req.SetBasicAuth("api", apiKey)
response, err := client.Do(req)
if err != nil {
return
}
defer response.Body.Close()
// Decode response.
err = json.NewDecoder(response.Body).Decode(&listDomainKeyResp)
return
}
Sample response 200:
{
"items": [
{
"selector": "s1",
"signing_domain": "example.com"
},
{
"selector": "s2",
"signing_domain": "example.com"
}
],
"paging": {
"first": "https://....",
"last": "https://....",
"next": "https://....",
"previous": "https://...."
}
}
Delete a domain key
curl -s --user `api:YOUR_API_KEY' -G \
https://api.mailgun.net/v1/dkim/keys
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class MGSample {
// ...
public static JsonNode listDomainKeys() throws UnirestException {
HttpResponse<JsonNode> request = Unirest.get("https://api.mailgun.net/v1/dkim/keys")
.basicAuth("api", API_KEY)
.asJson();
return request.getBody();
}
}
function list_domain_keys() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:PRIVATE_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v1/dkim/keys');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
def list_domain_keys():
return requests.get(
"https://api.mailgun.net/v1/dkim/keys",
auth=('api', 'YOUR_API_KEY'))
def get_domain_keys
RestClient.get("https://api:YOUR_API_KEY"\
"@api.mailgun.net/v1/dkim/keys")
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
public class InboxPlacementTests
{
public static void Main (string[] args)
{
Console.WriteLine (ListDomainKeys ().Content.ToString ());
}
public static IRestResponse ListDomainKeys ()
{
RestClient client = new RestClient ();
client.BaseUrl = new Uri ("https://api.mailgun.net/v1");
client.Authenticator =
new HttpBasicAuthenticator ("api",
"YOUR_API_KEY");
RestRequest request = new RestRequest ();
request.Resource = "dkim/keeys";
request.Method = Method.GET;
return client.Execute (request);
}
}
import (
"encoding/json"
"net/http"
)
type ListDomainKeyResp struct {
Items []DomainKey `json:"items"`
Page PagingResponse `json:"paging"`
}
type DomainKey struct {
SigningDomain string `json:"signing_domain"`
Selector string `json:"selector"`
Record Record `json:"dns_record"`
Page PagingResponse `json:"paging"`
}
type Record struct {
Active bool `json:"is_active"`
Cached []string `json:"cached"`
Name string `json:"name"`
Type string `json:"record_type"`
Valid string `json:"valid"`
Value string `json:"value"`
}
type PagingResponse struct {
Previous string `json:"previous"`
First string `json:"first"`
Next string `json:"next"`
Last string `json:"last"`
}
func ListDomainKeys() (listDomainKeyResp LitDomainKeyResp, err error) {
// creating HTTP request and returning response
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.mailgun.net/v1/dkim/keys", nil)
req.SetBasicAuth("api", apiKey)
response, err := client.Do(req)
if err != nil {
return
}
defer response.Body.Close()
// Decode response.
err = json.NewDecoder(response.Body).Decode(&listDomainKeyResp)
return
}
Sample response 200:
{
"message": "success"
}
Create a domain key
Sample response 200:
{
"dns_record": {
"cached": [],
"is_active": false,
"name": "s1._domainkey.example.com",
"record_type": "TXT",
"valid": "unknown",
"value": "k=rsa; p=public_key"
},
"selector": "s1",
"signing_domain": "example.com"
}
Sample response 401:
{
"message": "Invalid private key"
}