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.

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, block, or tag

If disabled, no spam filtering will occur for inbound messages.

If block, inbound spam messages will not be delivered.

If tag, inbound 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.

GET /domains/<domain>/credentials

Returns a list of SMTP credentials for the defined domain.

Parameter Description
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
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 yes or no
PUT /domains/<domain>/tracking/click

Updates the click tracking settings for a domain.

Parameter Description
active

yes, no, or htmlonly

If set to yes, links will be overwritten and pointed to our servers so we can track clicks.

If set to htmlonly, links will only be rewritten in the HTML part of a message.

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 Tracking Unsubscribes for more details.

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 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 getDomains() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.get("https://api.mailgun.net/v3/domains")
            .basicAuth("api", API_KEY)
            .queryString("skip", 0)
            .queryString("limit", 3)
            .asJson();

        return request.getBody();
    }
}
# 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)
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get('/domains', function (error, body) {
  console.log(body);
});

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 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 getDomain() throws UnirestException {

        HttpResponse<JsonNode> request = Unirest.get("https://api.mailgun.net/v3/domains/" + YOUR_DOMAIN_NAME)
            .basicAuth("api", API_KEY)
            .queryString("skip", 0)
           .queryString("limit", 3)
            .asJson();

        return request.getBody();
    }
}
# 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)
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get(`/domain/${DOMAIN}, function (error, body) {
  console.log(body);
});

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 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 addDomain() throws UnirestException {

        HttpResponse<JsonNode> jsonResponse = Unirest.post("https://api.mailgun.net/v3/domains")
            .basicAuth("api", API_KEY)
            .field("name", "YOUR_NEW_DOMAIN_NAME")
            .field("smtp_password", "supersecretpassword")
            .asJson();

        return jsonResponse.getBody();
    }
}
# 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)
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.post('/domains', {"name" : "YOUR_NEW_DOMAIN_NAME", "smtp_password" : "supersecret"}, function (error, body) {
  console.log(body);
});

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 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 deleteDomain() throws UnirestException {

        HttpResponse<JsonNode> request = Unirest.delete("https://api.mailgun.net/v3/domains/domain.example.com")
            .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 = 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")
}

.. code-block:: js

var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.delete('/domains/example.mailgun.org', function (error, body) {
  console.log(body);
});

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 = 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)
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get(`/domains/${DOMAIN}/credentials`, function (error, body) {
  console.log(body);
});

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.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 createCredentials() throws UnirestException {

        HttpResponse<JsonNode> jsonResponse = Unirest.post("https://api.mailgun.net/v3/domains/" + YOUR_DOMAIN_NAME +"/credentials")
            .basicAuth("api", API_KEY)
            .field("login", "alice@YOUR_DOMAIN_NAME.com")
            .field("password", "supersecretpassword")
            .asJson();

        return jsonResponse.getBody();
    }
}
# 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")
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.post(`/domains/${DOMAIN}/credentials`, {"login": "alice@YOUR_DOMAIN_NAME", "password": "secret"}, function (error, body) {
  console.log(body);
});

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 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 updatePassword() throws UnirestException {

        HttpResponse<JsonNode> jsonResponse = Unirest.put("https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/credentials/alice")
            .basicAuth("api", API_KEY)
            .field("password", "supersecret")
            .asJson();

        return jsonResponse.getBody();
    }
}
# 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
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.put(`/domain/${DOMAIN}/credentials/alice`, {"password" : "supersecret"}, function (error, body) {
  console.log(body);
});

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.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 deleteCredentials() throws UnirestException {

        HttpResponse<JsonNode> request = Unirest.delete("https://api.mailgun.net/v3/domains/"+ YOUR_DOMAIN_NAME +"/credentials/user")
            .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 = 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")
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.put(`/domains/${DOMAIN}/credentials/alice`, function (error, body) {
  console.log(body);
});

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.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 getConnections() throws UnirestException {

        HttpResponse<JsonNode> request = Unirest.get("https://api.mailgun.net/v3/domains/"+ YOUR_DOMAIN_NAME +"/connection")
            .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 = 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
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get(`/domains/${DOMAIN}/connection`, function (error, body) {
  console.log(body);
});

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.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 updateConnections() throws UnirestException {

        HttpResponse<JsonNode> jsonResponse = Unirest.put("https://api.mailgun.net/v3/domains/"+ YOUR_DOMAIN_NAME +"/connection")
            .basicAuth("api", API_KEY)
                    .field("require_tls", true)
                    .field("skip_verification", false)
                .asJson();

        return jsonResponse.getBody();
    }
}
# 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
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.put(`/domain/${DOMAIN}/connection`, {"require_tls": true, "skip_verification": false}, function (error, body) {
  console.log(body);
});

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.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 getDomainTracking() throws UnirestException {

        HttpResponse<JsonNode> request = Unirest.get("https://api.mailgun.net/v3/domains/" + YOUR_DOMAIN_NAME + "/tracking")
            .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 = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

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

}
// coming soon
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get(`/domains/${DOMAIN}/tracking`, function (error, body) {
  console.log(body);
});

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