Domains

This 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
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.

Parameter Description
name Name of the domain
PUT /domains/<domain>/verify

Verifies and returns a single domain, including credentials and DNS records. If the domain is successfully verified the message should be the following: Domain DNS records have been updated. 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 disabled or tag Disable, no spam filtering will occur for inbound messages. Tag, messages will be tagged with a spam header. See Spam Filter.
wildcard true or false Determines whether the domain will accept email for sub-domains.
DELETE /domains/<domain>

Delete a domain from your account.

Parameter Description
name Name of the domain
GET /domains/<domain>/credentials

Returns a list of SMTP credentials for the defined domain.

Parameter Description
name Name of the domain
limit Maximum number of records to return. (100 by default)
skip Number of records to skip. (0 by default)
POST /domains/<domain>/credentials

Creates a new set of SMTP credentials for the defined domain.

Parameter Description
name Name of the domain
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
name Name of the domain
login The user name, for example bob.bar
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.

Parameter Description
name Name of the domain
login The user name, for example bob.bar
GET /domains/<domain>/connection

Returns delivery connection settings for the defined domain.

Parameter Description
name Name of the domain
PUT /domains/<domain>/connection

Updates the specified delivery connection settings for the defined domain.

Parameter Description
require_tls

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 can not, the message will be delivered over a plaintext SMTP connection.

The default is False.

skip_verification

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.

Parameter Description
name Name of the domain (ex. domain.com)
PUT /domains/<domain>/tracking/open

Updates the open tracking settings for a domain.

Parameter Description
name Name of the domain (ex. domain.com)
PUT /domains/<domain>/tracking/click

Updates the click tracking settings for a domain.

Parameter Description
name Name of the domain (ex. domain.com)
PUT /domains/<domain>/tracking/unsubscribe

Updates unsubscribe tracking settings for a domain.

Parameter Description
name Name of the domain (ex. domain.com)

Example

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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse GetDomains() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        return mgRoot
            .path("/domains")
            .queryParam("skip", 0)
            .queryParam("limit", 3)
            .request()
            .buildGet()
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');

# Issue the call to the client.
$result = $mgClient->get("domains", array('limit' => 5, 'skip' => 10));
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);
    }

}
func GetDomains(domain, apiKey string) (int, []mailgun.Domain, error) {
  mg := mailgun.NewMailgun(domain, apiKey, "")
  return mg.GetDomains(-1, -1)
}

Sample response:

{
  "total_count": 1,
  "items": [
    {
      "created_at": "Wed, 10 Jul 2013 19:26:52 GMT",
      "smtp_login": "postmaster@samples.mailgun.org",
      "name": "samples.mailgun.org",
      "smtp_password": "4rtqo4p6rrx9",
      "wildcard": true,
      "spam_action": "disabled",
      "state": "active"
    }
  ]
}

Get a single domain.

curl -s --user 'api:YOUR_API_KEY' -G \
    https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse GetDomain() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        return mgRoot
            .path("/{domain}")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .request()
            .buildGet()
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->get("domains/$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);
    }

}
func GetSingleDomain(domain, apiKey string) (mailgun.Domain, []mailgun.DNSRecord, []mailgun.DNSRecord, error) {
  mg := mailgun.NewMailgun(domain, apiKey, "")
  return mg.GetSingleDomain(domains[0].Name)
}

Sample response:

{
  "domain": {
    "created_at": "Wed, 10 Jul 2013 19:26:52 GMT",
    "smtp_login": "postmaster@domain.com",
    "name": "domain.com",
    "smtp_password": "4rtqo4p6rrx9",
    "wildcard": false,
    "spam_action": "tag",
    "state": "active"
  },
  "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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse AddDomain() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        Form reqData = new Form();
        reqData.param("name", "YOUR_NEW_DOMAIN_NAME");
        reqData.param("smtp_password", "supersecretpassword");

        return mgRoot
            .path("/domains")
            .request(MediaType.APPLICATION_FORM_URLENCODED)
            .buildPost(Entity.entity(reqData, MediaType.APPLICATION_FORM_URLENCODED))
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_NEW_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->post("domains", array(
    'name'          => 'anothersample.mailgun.org',
    'smtp_password' => 'supersecretpassword'
));
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);
    }

}
func AddDomain(domain, apiKey string) error {
       mg := mailgun.NewMailgun(domain, apiKey, "")
       return mg.CreateDomain("YOUR_NEW_DOMAIN_NAME", "supersecretpassword", mailgun.Tag, false)
}

Sample response:

{
  "domain": {
    "name": "example.com",
    "created_at": "Fri, 22 Nov 2013 18:42:33 GMT",
    "wildcard": false,
    "spam_action": "disabled",
    "smtp_login": "postmaster@example.com",
    "smtp_password": "thiswontwork",
    "state": "active"
  },
  "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"
    }
  ],
  "message": "Domain has been created",
  "sending_dns_records": [
    {
      "record_type": "TXT",
      "valid": "valid",
      "name": "example.com",
      "value": "v=spf1 include:mailgun.org ~all"
    },
    {
      "record_type": "TXT",
      "valid": "valid",
      "name": "k1._domainkey.example.com",
      "value": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4G...."
    },
    {
      "record_type": "CNAME",
      "valid": "valid",
      "name": "email.example.com",
      "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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse DeleteDomain() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        return mgRoot
            .path("/domains/{domain}")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .request(MediaType.APPLICATION_FORM_URLENCODED)
            .buildDelete()
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'example.mailgun.org';

# Issue the call to the client.
$result = $mgClient->delete("domains/$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);
    }

}
func DeleteDomain(domain, apiKey string) error {
  mg := mailgun.NewMailgun(domain, apiKey, "")
  return mg.DeleteDomain("subdomain.example.com")
}

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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse GetCredentials() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        return mgRoot
            .path("/{domain}/credentials")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .request()
            .buildGet()
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->get("domains/$domain/credentials", array(
    'limit' => 5,
    'skip'  => 10
));
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);
    }

}
func GetCredentials(domain, apiKey string) (int, []mailgun.Credential, error) {
  mg := mailgun.NewMailgun(domain, apiKey, "")
  return mg.GetCredentials(-1, -1)
}

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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse CreateCredentials() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        Form reqData = new Form();
        reqData.param("login", "alice@YOUR_DOMAIN_NAME");
        reqData.param("password", "supersecret");

        return mgRoot
            .path("/{domain}/credentials")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .request(MediaType.APPLICATION_FORM_URLENCODED)
            .buildPost(Entity.entity(reqData, MediaType.APPLICATION_FORM_URLENCODED))
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->post("domains/$domain/credentials", array(
    'login'    => 'alice@YOUR_DOMAIN_NAME',
    'password' => 'secret'
));
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);
    }

}
func CreateCredential(domain, apiKey string) error {
  mg := mailgun.NewMailgun(domain, apiKey, "")
  return mg.CreateCredential("alice@YOUR_DOMAIN_NAME", "secret")
}

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/YOUR_DOMAIN_NAME/credentials/alice \
    -F password='abc123'
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse ChangeCredentialPassword() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        Form reqData = new Form();
        reqData.param("password", "supersecret");

        return mgRoot
            .path("/{domain}/credentials/{username}")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .resolveTemplate("username", "YOUR_MAILBOX_USER")
            .request(MediaType.APPLICATION_FORM_URLENCODED)
            .buildPut(Entity.entity(reqData, MediaType.APPLICATION_FORM_URLENCODED))
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$login= 'alice';

# Issue the call to the client.
$result = $mgClient->put("$domain/credentials/$login", array(
    'password' => 'supersecret'
));
def change_credential_password():
    return requests.put(
        "https://api.mailgun.net/v3/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/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 = "{domain}/credentials/{username}";
        request.AddUrlSegment ("username", "alice");
        request.AddParameter ("password", "supersecret");
        request.Method = Method.PUT;
        return client.Execute (request);
    }

}
// coming soon

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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse DeleteCredentials() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        return mgRoot
            .path("/domains/{domain}/credentials/{username}")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .resolveTemplate("username", "YOUR_CREDENTIAL_USERNAME")
            .request(MediaType.APPLICATION_FORM_URLENCODED)
            .buildDelete()
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$login = 'alice';

# Issue the call to the client.
$result = $mgClient->delete("domains/$domain/credentials/$login");
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);
    }

}
func DeleteCredential(domain, apiKey string) error {
  mg := mailgun.NewMailgun(domain, apiKey, "")
  return mg.DeleteCredential("alice")
}

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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse GetConnectionSettings() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        return mgRoot
            .path("/{domain}/campaigns/{campaign_id}/connection")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .request()
            .buildGet()
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->get("domains/$domain/connection", array());
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);
    }

}
// Coming soon

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 javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

public class MGSample {

    // ...

    public static ClientResponse UpdateConnectionSettings() {

        Client client = ClientBuilder.newClient();
        client.register(HttpAuthenticationFeature.basic(
            "api",
            "YOUR_API_KEY"
        ));

        WebTarget mgRoot = client.target("https://api.mailgun.net/v3");

        Form reqData = new Form();
        reqData.param("require_tls", "true");
        reqData.param("skip_verification", "false");

        return mgRoot
            .path("/domains/{domain}/connection")
            .resolveTemplate("domain", "YOUR_DOMAIN_NAME")
            .request(MediaType.APPLICATION_FORM_URLENCODED)
            .buildPut(Entity.entity(reqData, MediaType.APPLICATION_FORM_URLENCODED))
            .invoke(ClientResponse.class);
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');

# Issue the call to the client.
$result = $mgClient->put("domains/$domain/connection", array(
    'require_tls'       => 'true',
    'skip_verification' => 'false'
));
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);
    }

}
// Coming soon

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:

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"
  }
 }
}