Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

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.

cPanel API suspend_outgoing_email

Discussion in 'cPanel Developers' started by jaheller, May 31, 2017.

Tags:
  1. jaheller

    jaheller Registered

    Joined:
    May 31, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Germany
    cPanel Access Level:
    Root Administrator
    Dear CPANEL Community,

    I'm using this code to generate email accounts for users:
    Code:
    function create_email_account($xmlapi, $email, $password) {
        $req = array("email" => $email, "password" => $password, "quota" => 500, "domain" => EMAIL_DOMAIN);
        $response = $xmlapi->api2_query(CPANEL_USERNAME, "Email", "addpop", $req);
        $decoded = json_decode($response, true);
        return get_cpanel_reason($decoded, "Failed to create email account for an unknown reason.");
    }
    
    I use the official API:
    GitHub - CpanelInc/xmlapi-php: A PHP Class for Interacting with cPanel's XML-API

    All in all, this works fine. But now I would like to know how I can disable (suspend) an account from sending emails.
    I've found WHM API 1 Functions - suspend_outgoing_email - Software Development Kit - cPanel Documentation this library, any idea how to call this function? Because all I tried resulted in errors.

    I tried using this function I wrote:
    Code:
    function suspend_email_account($xmlapi, $email){
        $req = array("user" => "some@mail.com");
        $response = $xmlapi->api1_query(CPANEL_USERNAME, "Account", "suspendacct", $req);
        $decoded = json_decode($response, true);
        return ($decoded);
    }
    
    Running the code I get:
    Code:
    array(8) { ["apiversion"]=> string(1) "1" ["type"]=> string(5) "event" ["module"]=> string(7) "Account" ["func"]=> string(11) "suspendacct" ["source"]=> string(6) "module" ["data"]=> array(1) { ["result"]=> string(0) "" } ["event"]=> array(2) { ["result"]=> int(0) ["reason"]=> string(110) "Account::suspendacct() failed: Can't use an undefined value as a subroutine reference at cpanel.pl line 1856. " } ["error"]=> string(110) "Account::suspendacct() failed: Can't use an undefined value as a subroutine reference at cpanel.pl line 1856. " }
    
    Any idea where's my fault located?
     
    #1 jaheller, May 31, 2017
    Last edited by a moderator: May 31, 2017
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,419
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    The following WHM API 1 function is only usable on the account username, as opposed to individual email accounts:

    WHM API 1 Functions - suspend_outgoing_email - Software Development Kit - cPanel Documentation

    You can use the following cPanel UAPI function if you want to prevent authenticated logins to an email account:

    https://documentation.cpanel.net/display/SDK/UAPI+Functions+-+Email%3A%3Asuspend_login

    If you prefer to use the WHM API 1 function for the account username, here's an example of a PHP script using a WHM API 1 function:

    https://github.com/CpanelInc/xmlapi-php/blob/master/Examples/killdns_example.php

    Thank you.
     
Loading...

Share This Page