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

Description

This function modifies a mail exchanger's type. 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::set_always_accept

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

Notes:

  • This function only affects the cPanel configuration. You must configure the mail exchanger's DNS entry separately.
  • This function is similar to the cPanel API 2 Email::setmxcheck function, but hooks and custom event handlers parse them as unique calls. 

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=setalwaysaccept&domain="example.com"&mxcheck="auto"&user="cpaneluser"


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.
 
// Change example.com's mx type to local.
$set_mx_type = $cpanel->api2(
    'Email', 'setalwaysaccept', 
    array(
        'domain'                => 'example.com', 
        'mxcheck'               => 'local',
        'user'                  => 'cpaneluser',
    ) 
);


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.
 
# Change example.com's mx type to local.
my $set_mx_type = $cpliveapi->api2(
    'Email', 'setalwaysaccept',
    { 
        'domain'                => 'example.com', 
        'mxcheck'               => 'local',
        'user'                  => 'cpaneluser',
    }
);


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 setalwaysaccept domain=example.com mxcheck=local user=cpaneluser


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": "setalwaysaccept",
    "data": [
      {
        "statusmsg": "Set Always Accept Status to: local",
        "status": 1,
        "checkmx": {
          "warnings": [
            
          ],
          "issecondary": 0,
          "local": 1,
          "detected": "local",
          "remote": 0,
          "isprimary": 1,
          "changed": 1,
          "secondary": 0,
          "mxcheck": "local"
        },
        "local": 1,
        "remote": 0,
        "detected": "local",
        "mxcheck": "local",
        "secondary": 0,
        "results": "Set Always Accept Status to: local"
      }
    ],
    "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
domainstring

Required

The mail exchanger's domain.

A valid domain on the cPanel account.

example.com
mxcheckstring

Required

The mail exchanger type.

 

  • auto — Allow cPanel to determine the appropriate role.
  • local — Always accept the domain's mail.
  • secondary — Accept mail until a higher priority mail server is available.
  • remote — Do not accept mail.
auto
userstring

Required

The cPanel account username.

The cPanel account's username.cpaneluser

Returns

ReturnTypeDescriptionPossible valuesExample
statusmsgstringA message of success or a reason for failure.
  • A message of success that includes the new type.
  • A string that describes an error.
Set Always Accept Status to: local
statusBooleanWhether the function succeeded.
  • 1 — The function succeeded.
  • 0 — The function failed.
1
checkmxhashA hash of the mail exchanger's data.This hash contains the warnings array and the issecondary, local, detected, remote, isprimary, changed, secondary, and mxcheck returns. 

warnings

array

An array of warning messages, if any exist.

The function returns this array in the checkmx hash.

One or more warning messages.
 Click to view...
Auto Detect of MX configuration not possible due to non-resolving MX entries.  Defaulting to last known setting: local.

issecondary

Boolean

Whether the mail exchanger is a secondary exchanger.

The function returns this value in the checkmx hash.

  • 1 — Secondary.
  • 0Not secondary.

0

local

Boolean

Whether the mail exchanger is a local exchanger.

The function returns this value in the checkmx hash.

  • 1 — Local.
  • 0Not local.
0

detected

string

The mail exchanger type.

The function returns this value in the checkmx hash.

  • auto
  • local
  • secondary
  • remote
auto

remote

Boolean

Whether the mail exchanger is a remote exchanger.

The function returns this value in the checkmx hash.

  • 1 — Remote.
  • 0Not remote.
0

isprimary

Boolean

Whether the mail exchanger is the primary mail exchanger.

The function returns this value in the checkmx hash.

  • 1 — Primary.
  • 0Not primary.
0

changed

Boolean

Whether a change occurred during the function.

The function returns this value in the checkmx hash.

  • 1 — Change occurred.
  • 0No change.
1

secondary

Boolean

Whether the mail exchanger is a secondary exchanger.

The function returns this value in the checkmx hash.

  • 1 — Secondary.
  • 0Not secondary.

0

mxcheck

string

The mail exchanger type.

The function returns this value in the checkmx hash.

  • auto
  • local
  • secondary
  • remote
auto
localBooleanWhether the mail exchanger is a local exchanger.
  • 1 — Local.
  • 0Not local.
0
remoteBoolean

Whether the mail exchanger is a remote exchanger.

  • 1 — Remote.
  • 0Not remote.
0
detectedstring

The mail exchanger type.

  • auto
  • local
  • secondary
  • remote
auto
mxcheckstring

The mail exchanger type.

  • auto
  • local
  • secondary
  • remote
auto
secondaryBoolean

Whether the mail exchanger is a secondary exchanger.

  • 1 — Secondary.
  • 0Not secondary.

0

resultsstringA message of success or a reason for failure.
  • A message of success that includes the new type.
  • A string that describes an error.
Set Always Accept Status to: local
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