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!

Add and remove Email user Account - Crear y Eliminar emails de usuarios

Discussion in 'cPanel Developers' started by PCDrivers, Oct 16, 2012.

  1. PCDrivers

    PCDrivers Registered

    Joined:
    Nov 27, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    51
    cPanel Access Level:
    Root Administrator
    [ENGLISH]
    This example is using "XML API PHP Class"

    You can download that on:
    https://github.com/CpanelInc/xmlapi-php

    [SPANISH]
    Esto es un ejemplo utilizando la clase "XML API PHP Class"

    Puedes bajarla desde la siguiente dirección:
    https://github.com/CpanelInc/xmlapi-php


    Example for creating email account:
    Ejemplo de creación de una cuenta
    PHP:
    <?php
    // Connect to cPanel API
    include('xmlapi.php');

    //  Checking script
    $ip '127.0.0.1';
    $cpuser 'yourusername';  // Username on cPanel / Usuario de cPanel
    $cppass 'password'// Your Password on cPanel / Contraseña de cPanel

    $xmlapi = new xmlapi($ip$cpuser $cppass );  // Connection
    // Change port to cPanel User System and not WHM
    // Cambiamos el puerto de cPanel al de usuarios
    print_r($xmlapi->set_port("2083")); 

    // You must write cPanel username account for creating emails
    // Debe de escribir el usuario de cPanel para crear los emails
    $username "username"

    $args = array();
    //email_username, email_password, [U]Email_Quota[/U] and email_domain
    $args[0] = "emailaccount@domain.tld";
    $args[1] = "password";
    $args[2] = "200"// Account quota (in Mb or Unlimited)
    $args[3] = "domain.tld";
    print_r($xmlapi->addpop($username,$args));
    ?>
    -
    For Deleting Email Accounts you must made some changes in original Class File. Adding the lines:
    Para la eliminación de cuentas de Email, debe hacer algunos cambios en la clase original. Añadiendo las líneas:

    After that
    Después de este código

    Code:
    	public function addpop($username, $args) {
    		##############################
    		...........................................................
    		##############################
    		}
    		return $this->api1_query($username, 'Email', 'addpop', $args);
    	}
    
    Add these one
    Añada este otro

    Code:
    	// This API1 function REMOVE a emailaccount for a specific user.
    	public function delpop($username, $args) {
    		if (!isset($username) || !isset($args)) {
    			error_log("delpop requires that a user and args are passed to it");
    			return false;
    		}
    		if (is_array($args) && (sizeof($args) < 2)) {
    			error_log("delpop requires that args at least contains an 'emailaccount as $arg[0]', 'domain as $arg[2]'");
    			return false;
    		}
    		return $this->api1_query($username, 'Email', 'delpop', $args);
    	}
    
    And that is the example code
    Y aquí el código de ejemplo de utilización
    PHP:
    <?php
    // Connect to cPanel API
    include('xmlapi.php');

    //  Checking script
    $ip '127.0.0.1';
    $cpuser 'yourusername';  // Username on cPanel
    $cppass 'password'// Your Password on cPanel

    $xmlapi = new xmlapi($ip$cpuser $cppass );  // Connection
    print_r($xmlapi->set_port("2083")); // Change port to cPanel User System and not WHM

    $username "username"// You must write cPanel username account for creating emails

    $args = array();
    $args[0] = "account@domain.tld";  // Email Account to remove
    //$args[1] = "nothing";
    $args[2] = "domain.tld"// Domain Account

    print_r($xmlapi->delpop($username,$args));

    ?>
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice