Page tree
Skip to end of metadata
Go to start of metadata

 

Description

This function lists Mail Exchanger (MX) records.

Examples 


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/Email/list_mxs?domain=example.com

Note:

This example calls the UAPI function via a cPanel session. For more information, read our Guide to UAPI documentation. 

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// List example.com's MX record.
$get_mx_list = $cpanel->uapi(
    'Email', 'list_mxs',
    array(
        '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 example.com's MX record.
my $get_mx_list = $cpliveapi->uapi(
    'Email', 'list_mxs',
    {
        'domain'        => 'example.com',
    }
);

Note:

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

 

 cPanel Template Toolkit
<!-- Get a list of example.com's mail exchangers, then display the mx values. -->
[% data = execute( 'Email', 'list_mxs', { 'domain' => 'example.com' } ); %]
[% FOREACH q = data.entries.mx %]
     <p>
         [% q %]
     </p>
[% END %]
  
<!-- Get only the mx values. -->
[% execute('Email', 'list_mxs', { 'domain' => 'example.com' } ).data.entries.mx %]

Note:

For more information, read our Guide to Template Toolkit documentation. 

 

 Command Line
uapi --user=username Email list_mxs domain=example.com

Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • For more information and additional output options, read our Guide to UAPI documentation or run the uapi --help command. 
  • We introduced this functionality in cPanel & WHM version 56.

 Output (JSON)
{  
   "messages":null,
   "errors":null,
   "status":1,
   "metadata":{  
      "transformed":1
   },
   "data":[  
      {  
         "statusmsg":"Fetched MX List",
         "entries":[  
            {  
               "mx":"newmx.example.com",
               "priority":"0",
               "domain":"example.com",
               "entrycount":1,
               "row":"odd"
            },
            {  
               "mx":"mail.example.com",
               "priority":"5",
               "domain":"example.com",
               "entrycount":2,
               "row":"even"
            },
            {  
               "mx":"mx.example.com",
               "priority":"10",
               "domain":"example.com",
               "entrycount":3,
               "row":"odd"
            },
            {  
               "mx":"mail4.example.com",
               "priority":"15",
               "domain":"example.com",
               "entrycount":4,
               "row":"even"
            }
         ],
         "status":1,
         "local":0,
         "detected":"local",
         "remote":0,
         "mx":"newmx.example.com",
         "domain":"example.com",
         "secondary":0,
         "mxcheck":"local",
         "alwaysaccept":1
      }
   ]
}

Note:

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

Parameters

ParameterTypeDescriptionPossible valuesExample
domainstring

The domain to query.

If you do not use this parameter, the function returns MX records for all of the cPanel account's domains.

A valid domain on the account.

example.com

Returns

ReturnTypeDescriptionPossible valuesExample
statusmsgstringA message of success, or an error message.
  • A message of success that begins with Added entry:
  • An error message.

Fetched MX List

entriesarray of hashesAn array of hashes of mail exchangers.

Each hash includes the mx, priority, domain, entrycount, and row returns.

 

mx

string

The mail exchanger's name.

The function returns this value in the entries hash.

A valid mail exchanger name.

newmx.example.com

priority

integer

The mail exchanger's priority value.

The function returns this value in the entries hash.

An integer.

5

domain

string

The mail exchanger's domain.

The function returns this value in the entries hash.

A valid domain name 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.

  • even
  • odd
odd
statusBooleanWhether the function succeeded.
  • 1 — Success.
  • 0 — Failure.
1
localBooleanWhether the domain's highest priority mail exchanger is a local mail exchanger.
  • 1 — Local.
  • 0Not local.
1
detectedstringThe domain's highest-priority mail exchanger's type.
  • auto
  • local
  • remote
  • secondary
local
remoteBooleanWhether the domain's highest-priority mail exchanger is remote.
  • 1 — Remote.
  • 0Not remote.
0
mxstringThe domain's highest-priority mail exchanger's name.A valid mail exchanger on the domain or cPanel account.newmx.example.com
domainstringThe domain.A valid domain on the cPanel account.example.com
secondaryBooleanWhether the domain's highest-priority mail exchanger is secondary.
  • 1 — Secondary.
  • 0Not secondary.
0
mxcheckstringThe domain's highest-priority mail exchanger's type.
  • auto
  • local
  • remote
  • secondary
auto
alwaysacceptBooleanWhether the domain's highest-priority mail exchanger accepts local mail.
  • 1 — Accept local mail.
  • 0 — Does not accept local mail.
1