Description

This function lists mail exchangers.

 For more information about MX record settings, read our Edit MX Entry documentation.

We strongly recommend that you use the following UAPI function instead of this function:


This function is identical to the cPanel API 2 Email::listmxs function. 


Examples 




https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=listmx&domain="example.com"



$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// List the mail exchangers for example.com.
$list_all_mxs = $cpanel->api2(
    'Email', 'listmx', 
    array(
		'user'					=> 'user',
		'domain'                => 'example.com', 
    ) 
);



my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# List the mail exchangers for example.com.
my $list_all_mxs = $cpliveapi->api2(
    'Email', 'listmx',
    { 
		'user'					=> 'user',
        'domain'                => 'example.com', 
    }
);




cpapi2 --user=username Email listmx user=user domain=example.com



{
  "cpanelresult": {
    "apiversion": 2,
    "func": "listmx",
    "data": [
      {
        "statusmsg": "Fetched MX List",
        "status": 1,
        "entries": [
          {
            "priority": "0",
            "mx": "mail.example.com",
            "domain": "example.com",
            "entrycount": 1,
            "row": "odd"
          },
          {
            "priority": "7",
            "mx": "mail2.example.com",
            "domain": "example.com",
            "entrycount": 2,
            "row": "even"
          },
          {
            "priority": "15",
            "mx": "mail6.example.com",
            "domain": "example.com",
            "entrycount": 3,
            "row": "odd"
          }
        ],
        "local": 1,
        "remote": 0,
        "detected": "local",
        "mx": "mail",
        "domain": "example.com",
        "mxcheck": "auto",
        "secondary": 0,
        "alwaysaccept": 0
      }
    ],
    "event": {
      "result": 1
    },
    "module": "Email"
  }
}



Parameters

ParameterTypeDescriptionPossible valuesExample
userstring

Required

The account's username.

A valid username on the cPanel account.user
domainstring

The domain to query.

If you do not use this parameter, the function returns a list of all mail exchangers on the cPanel account.

A valid domain on the cPanel account.

example.com

Returns

ReturnTypeDescriptionPossible valuesExample
statusmsgstringA message of success or a reason for failure.
  • Fetched MX List
  • A string that describes an error.

Fetched MX List

statusBooleanWhether the function succeeded.
  • 1 — The function succeeded.
  • 0 — The function failed.
1
entriesarray of hashesAn array of hashes of a domain's mail exchangers.Each hash contains the priority, mx, domain, entrycount, and row returns. 

priority

integer

The mail exchanger's priority value.

The function returns this value in the entries hash.

A positive integer.

5

mx

string

The mail exchanger name.

The function returns this value in the entries hash.

A valid mail exchanger on the domain or cPanel account.

mail.example.com

domain

string

The mail exchanger's domain.

The function returns this value in the entries hash.

A valid domain on the cPanel account.

example.com

entrycount

integer

The mail exchanger's order in the list of priorities.

The function returns this value in the entries hash.

A positive integer.

For example, the mail exchanger with the highest priority returns 1, and the next highest priority returns 2.

1

row

string

Whether the mail exchanger is an odd or an even entry.

The function returns this value in the entries hash.

  • odd
  • even
odd
localBooleanWhether the domain's highest-priority mail exchanger is a local mail exchanger.
  • 1 — Local.
  • 0Not local.

1

remoteBooleanWhether the domain's highest-priority mail exchanger is remote.
  • 1 — Remote.
  • 0Not remote.
0
detectedstringThe domain's highest-priority mail exchanger's type.
  • auto
  • local
  • remote
  • secondary
auto
mxstringThe domain's highest-priority mail exchanger's name.A valid mail exchanger on the domain or cPanel account.mail.example.com
domainstringThe domain.A valid domain on the cPanel account.example.com
mxcheckstringThe domain's highest-priority mail exchanger's type.
  • auto
  • local
  • remote
  • secondary
auto
secondaryBooleanWhether the domain's highest-priority mail exchanger is secondary.
  • 1 — Secondary.
  • 0Not secondary.
0
alwaysacceptBooleanWhether the domain's highest-priority mail exchanger accepts local mail.
  • 1 — Accept local mail.
  • 0 — Does not accept local mail.
1
reasonstring

A reason for failure.

This function only returns a reason value if it failed. 


A string that describes the error.

This is an error message.
resultBoolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1