cPanel API 2 Functions - Email::addmx
The cPanel API 2 system is deprecated. We strongly recommend that you use UAPI instead of cPanel API 2.
Description
This function creates an MX record. For more information about MX record settings, read our Email Routing Configuration documentation.
We strongly recommend that you use the following UAPI function instead of this function:
-
Email::add_mx
— This function creates a Mail Exchanger (MX) record.
When you disable the DNS role, the system disables this function.
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=addmx&domain="example.com"&exchange="newmx.example.com"&oldexchange="oldmail"&oldpreference="1"&alwaysaccept="auto"
For more information, read our Calls from the WHM API documentation.
LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Replace mail.example.com with an MX entry for newmx.example.com.
$add_new_mx = $cpanel->api2(
'Email', 'addmx',
array(
'alwaysaccept' => 'auto',
'domain' => 'example.com',
'exchange' => 'newmx.example.com',
'oldexchange' => 'mail',
'oldpreference' => '5',
'preference' => '15',
)
);
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.
# Replace mail.example.com with an MX entry for newmx.example.com.
my $add_new_mx = $cpliveapi->api2(
'Email', 'addmx',
{
'alwaysaccept' => 'auto',
'domain' => 'example.com',
'exchange' => 'newmx.example.com',
'oldexchange' => 'mail',
'oldpreference' => '5',
'preference' => '15',
}
);
For more information, read our Guide to the LiveAPI System.
cPanel Tag System (deprecated)
- 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 addmx domain=example.com exchange=newmx.example.com oldexchange=mail oldpreference=5 preference=15 alwaysaccept=auto
For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help
command.
Output (JSON)
{
"cpanelresult": {
"apiversion": 2,
"func": "addmx",
"data": [
{
"statusmsg": "Added entry: example.com.\tIN\tMX\t0\tnewmx.\n\nBind reloading on server1 using rndc zone: [example.com]\n",
"status": 1,
"checkmx": {
"warnings": [
],
"issecondary": 0,
"local": 0,
"detected": "local",
"remote": 0,
"isprimary": 1,
"changed": 0,
"secondary": 0,
"mxcheck": "auto"
},
"results": "Added entry: example.com.\tIN\tMX\t0\tnewmx.\n\nBind reloading on server1 using rndc zone: [example.com]\n"
}
],
"event": {
"result": 1
},
"module": "Email"
}
}
Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.
Parameters
Parameter | Type | Description | Possible values | Example |
---|---|---|---|---|
alwaysaccept |
string | Whether the mail exchanger accepts mail for its domain. This parameter defaults to
|
|
auto |
domain |
string | Required The new mail exchanger's domain. |
A valid domain on the cPanel account. |
example.com |
exchange , newmx , or exchanger |
string | Required The new mail exchanger's name. |
A valid mail exchanger name. |
newmx.example.com |
oldexchange , oldmx , or oldexchanger |
string | Required The name of an existing mail exchanger, which the new exchanger replaces. |
A valid mail exchanger on the cPanel account. | mail |
oldpreference or oldpriority |
integer | Required The If multiple MX entries match the |
A positive integer. | 5 |
preference or priority |
integer | Required The new mail exchanger's priority value. |
A positive integer. Note:It is common practice to set a priority value that is divisible by five. |
15 |
Returns
Return | Type | Description | Possible values | Example |
---|---|---|---|---|
statusmsg |
string | A message of success or a reason for failure. |
|
Added entry: example.com.\tIN\tMX\t0\tnewmx.\n\nBind reloading on server1 using rndc zone: [example.com]\n
|
status |
Boolean | Whether the function succeeded. |
|
1 |
checkmx |
hash | A hash of the mail exchanger's data. | This hash includes the warnings , issecondary , local , detected , remote , isprimary , changed , secondary , and mxcheck returns. |
|
|
string | Warning messages, if any exist. The function returns this value in the |
One or more warning messages. | Auto Detect of MX configuration not possible due to non-resolving MX entries. Defaulting to last known setting: local.
|
|
Boolean |
Whether the mail exchanger is a secondary exchanger. The function returns this value in the |
|
|
|
Boolean | Whether the mail exchanger is a local exchanger. The function returns this value in the |
|
0 |
|
string | The mail exchanger type. The function returns this value in the |
|
auto |
|
Boolean | Whether the mail exchanger is a remote exchanger. The function returns this value in the |
|
0 |
|
Boolean | Whether the mail exchanger is the primary mail exchanger. The function returns this value in the |
|
0 |
|
Boolean | Whether a change occurred during the function. The function returns this value in the |
|
1 |
|
Boolean | Whether the mail exchanger is a secondary exchanger. The function returns this value in the |
|
|
|
string | The mail exchanger type. The function returns this value in the |
|
auto |
results |
string | A message of success or a reason for failure. |
|
Added entry: example.com.\tIN\tMX\t0\tnewmx.\n\nBind reloading on server1 using rndc zone: [example.com]\n
|
reason |
string | A reason for failure. Note:This function only returns a |
A string that describes the error. |
This is an error message. |
result |
Boolean | Whether the function succeeded. |
|
1 |