The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

MX Entries and the API

Discussion in 'cPanel Developers' started by rinkleton, Feb 24, 2017.

Tags:
  1. rinkleton

    rinkleton Well-Known Member

    Joined:
    Jul 16, 2015
    Messages:
    51
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Cleveland
    cPanel Access Level:
    Root Administrator
    Trying to make sense of the API (uapi) fields as they relate to an account, a domain, and a single mx record.

    The section in cpanel under mx entry labeled "Email Routing" with options of auto, local, remote, backup seems pretty obviously "per domain". In the api, it seems like this param general is 'mxcheck' and the Email::list_mxs seems to confirm this. However in the Email::change_mx and Email::add_mx things get a little weird.

    change_mx has no param named 'mxcheck' however it does have one called 'alwaysaccept' that, according to the documentation, accepts the same 4 possible values listed above. Yet the example value shows "0". It seems like possible values list is a mistake, particularly because the email routing isn't per mx entry, but rather per domain.

    add_mx has 'alwaysaccept' with possible values of 0, 1. Which makes sense. However going back to the list_mxs documentation, the description of the 'mxcheck' field is that it returns the value of the highest priority mx record. So that makes it sound like the 'mxcheck' field is per mx record not per domain.

    Then over to the Email::set_always_accept function, the params accepted are domain, mxcheck, alwaysaccept. domain and mxcheck make sense as they mostly seems to be per domain things. However setting alwaysaccept doesn't seem to work. From what I can tell it seems like it is a readonly field based on the mxcheck value (or detected value if mxcheck is auto). So what is the point of setting it, if you can't change it? And it's not in the cpanel interface, so not sure why it's listed in the api as something that can be changed?

    There are also some verbiage differences when it comes to the 'alwaysaccept' field. Particularly the presence and absense of the word 'locally'. Wondering if that is on purpose or accident?

    Ultimately my questions are:
    Is the Email Routing field truely per domain and not technically per MX record?
    Is the alwaysaccept field in uapi - Email::set_always_accept actually setable?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    For the purposes of hooks, the corresponding API function when using the "Email Routing" option in cPanel is the following cPanel API 2 function:

    cPanel API 2 Functions - Email::setmxcheck - Software Development Kit - cPanel Documentation

    You can verify this by turning on debug mode under the "Development" tab in "WHM >> Tweak Settings", making a change to the email routing configuration via "cPanel >> Email Routing", and then watching the output from /usr/local/cpanel/logs/error_log. You'll notice an entry like this:

    Code:
    [2017-03-03 09:44:18 -0600] info [cpanel] ---debug_hooks---
    [2017-03-03 09:44:18 -0600] info [cpanel]             msg: No hooks found for traversed context
    [2017-03-03 09:44:18 -0600] info [cpanel]         context: Cpanel::Api2::Email::setmxcheck
    [2017-03-03 09:44:18 -0600] info [cpanel]           stage: pre
    [2017-03-03 09:44:20 -0600] info [cpanel] ---debug_hooks---
    [2017-03-03 09:44:20 -0600] info [cpanel]             msg: No hooks found for traversed context
    [2017-03-03 09:44:20 -0600] info [cpanel]         context: Cpanel::Api2::Email::setmxcheck
    [2017-03-03 09:44:20 -0600] info [cpanel]           stage: post
    However, regarding UAPI, the corresponding UAPI function is:

    UAPI Functions - Email::set_always_accept - Software Development Kit - cPanel Documentation

    It is per-domain name, and corresponds with entries like this in the /var/cpanel/users/$username file associated with the account:

    Code:
    MXCHECK-domain.tld=local
    MXCHECK-addon-domain.tld=remote
    Yes, for instance, if the existing "Email Routing" setting for a domain name is "Auto", and the domain name's MX record resolves to a remote server, then running the following command ensures the "Email Routing" switches it to "Local" and moves the domain name to the /etc/localdomains file:

    Code:
    uapi --user=username Email set_always_accept domain=example.com alwaysaccept=1
    This would allow someone to leave the setting at "Auto" for all domain names, and ensure the domain name always remains in the /etc/localdomains file.

    Thank you.
     
  3. rinkleton

    rinkleton Well-Known Member

    Joined:
    Jul 16, 2015
    Messages:
    51
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Cleveland
    cPanel Access Level:
    Root Administrator
    Doing this always changes the mxcheck field to 'local'. How is it possible to have mxcheck be 'auto' and alwaysaccept be 1? Even changing mxcheck to auto after this forces alwaysaccept back to 0.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Could you open a support ticket using the link in my signature so we can take a closer look? You can post the ticket number here and we will update this thread with the outcome.

    Thank you.
     
Loading...

Share This Page