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.

Listing email forwarders

Discussion in 'E-mail Discussions' started by isandell, Jul 12, 2009.

  1. isandell

    isandell Member

    Joined:
    Jul 12, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    I am familiar with cpanel but only from user interface ie I dont understand API etc.

    I now need to be able to get list of email forwarders so that I can format into a web page. Can I do this?

    Thanks

    Ian
     
  2. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Look in /etc/valiases and you'll find the lists you need in there
     
  3. isandell

    isandell Member

    Joined:
    Jul 12, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    I appear not to have a sub dir called valiases in /etc

    Ian
     
  4. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Let me guess ...

    You aren't a server administrator but rather just an end user? :rolleyes:

    The directory /etc/valiases is on every Cpanel server and is the folder
    that contains the list of email forwarders saved for each domain in a
    file named with the domain name for the account.

    If you are logged into SSH and your /etc shows something differently
    then you are logged in using a regular user account instead of root
    and are locked in a jailshell environment and not looking at the real /etc

    Login as root and go to /etc/valiases !!!

    If you are an end user and don't have administrator access and looking
    for email forwarders for your domain only then you need to login to your
    cpanel and go to "Forwarders" under the mail section of your control panel
    and you can view the list of email forwarders you have setup for your
    domain from there.
     
  5. isandell

    isandell Member

    Joined:
    Jul 12, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    Yes, I am an end user. I know how to view and how to setup and change email forwarders but what I want to do is to enable domain user to see the email forwarders.

    For example, I have email forwarders for committee@myclub.com I would like committee members to be able to see to whom committee@myclub.com is being forwarded, without having them to log on to cpanel.

    I guess that this is not possible, or you dont know how to do this?
     
  6. isandell

    isandell Member

    Joined:
    Jul 12, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    In case anyone else is looking to do this, this is what worked for me.

    Quick and dirty

    <?php
    $file = file_get_contents ('http://username:password@www.mydomain.co.uk:2082/frontend/hostpapa-x3-uk/mail/fwds.html?domain=&itemsperpage=100');

    echo $file;
    ?>

    This is like a text version of the cpanel screen, but it looks a bit messy, so I used some simple text matching with preg_match to extract the email addresses and format them nicely on a webpage.

    Happy to share script if anyone wants.
     
  7. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    That code is likely to break in future versions of cPanel. I recommend using our APIs instead, which are available to you over ports 2082/2083 (the cPanel ports).

    To make it easier to use our APIs, Matt has created a PHP 5 class to allow you to easily interact with our APIs via PHP 5. You can download this PHP 5 class at:

    http://forums.cpanel.net/f42/xmlapi-php-class-111897.html

    As far as the API function you would need to use to list forwarders, it is an API2 function which is documented at:

    Api2ListForwarders < AllDocumentation/AutomationIntegration < TWiki

    So, figure out the API2 call you want to make, just call it via that PHP class and you'll get the information you need in XML format.

    This function can also take a regex= input parameter where you can search for a specific email account using Perl regular expressions.

    Those are the basic building blocks for what you are looking to accomplish, let me know what clarifications or assistance you need with doing this.
     
  8. isandell

    isandell Member

    Joined:
    Jul 12, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for reply.

    I would like understand better so a couple of question, if I may.

    First, when you say that my code is likely to break in future versions of cPanel, is this because of likely syntax changes in calling the html page or something more fundamental?

    Second, I did look all through the Wiki and and found it completely incomprehensible. How does one use a bit of code like

    "<?cp Email::listforwards(% %,dest,forward) domain=exampledomain.com ?>"

    Where does it go and how does it get called? Prolly pretty dumb questions but as I said, I dont understand API.

    Thanks
     
  9. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Those on our EDGE branch will notice our new XSRF protection. The method we used for implementing this would require either 1) disabling XSRF protection so your script can work or 2) substantial re-coding of your script so it can work with our XSRF protection.

    No problem,

    Basically what you need to do is call an API2 function, which is easy with the PHP 5 class since you just call $xmlapi->api2_query() and it handles all the messy XML for you.

    $xmlapi->api2_query() takes many parameters:
    - First parameter is the username for the cPanel user you want to execute this as. If you are running this via port 2082/2083, this will always be the username of the cPanel account you are accessing. So your first parameter is: Your cPanel Username

    - Second parameter is the Module you want to access. API2 is structured as Module::function. So, with that code sample above, that would make the Module be: Email. So your second parameter is: Email

    - The third parameter is the Function you want to execute. With the code sample above, the function would be: listforwards. So your third parameter is: listforwards

    So far we have $xmlapi->api2_query($cPanelUser, 'Email', 'listforwards')

    Try this first, then we'll worry about narrowing down which forwarders are returned.
     
  10. isandell

    isandell Member

    Joined:
    Jul 12, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    Sort of understand that. When is a new version of cPanel likely to be released, months or years?

    I get

    Missing argument 4 for xmlapi::api2_query()

    Any ideas?

    Thanks

    Ian
     
  11. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The forth parameter is an associative array, so you would pass in array(domain => 'example.com') where example.com is your domain.
     
Loading...

Share This Page