Child pages
  • cPanel API 2 Functions - Email::listmxs
Skip to end of metadata
Go to start of metadata

Description

This function lists mail exchangers. For more information about MX record settings, read our Edit MX Entry documentation.

Warning:

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

  • Email::list_mxs

    Error rendering macro 'excerpt-include' : No link could be created for 'UAPI Functions - Email::list_mxs'.

Note:

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

Important:

In cPanel & WHM version 76 and later, when you disable the DNS role, the system disables this function. For more information, read our How to Use Server Profiles documentation.

Examples 


 WHM API (JSON)
https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=listmxs&domain="example.com"


Note:

 For more information, read our Calls from the WHM API documentation.

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


Note:

For more information, read our Guide to the LiveAPI System.

 LiveAPI Perl Module
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', 'listmxs',
    { 
		'user'					=> 'user',
        'domain'                => 'example.com', 
    }
);


Note:

For more information, read our Guide to the LiveAPI System.

 cPanel Tag System (deprecated)


Warnings:

  • In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.
  • cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
  • For more information, read our Deprecated cPanel Tag Usage documentation.

 Command Line
cpapi2 --user=username Email listmxs user=user domain=example.com


Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • You must run the --user=username command.
  • For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help command.
  • If you run CloudLinux™, you must use the full path of the cpapi2 command:

    /usr/local/cpanel/bin/cpapi2

 Output (JSON)
{
  "cpanelresult": {
    "apiversion": 2,
    "func": "listmxs",
    "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"
  }
}


Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
userstring

Required

The cPanel 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.

Note:

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