Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    11

    Default Listing email forwarders

    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. #2
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Default

    Look in /etc/valiases and you'll find the lists you need in there

  3. #3
    Member
    Join Date
    Jul 2009
    Posts
    11

    Default

    I appear not to have a sub dir called valiases in /etc

    Ian

  4. #4
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Exclamation

    Quote Originally Posted by isandell View Post
    I appear not to have a sub dir called valiases in /etc

    Ian
    Let me guess ...

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

    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. #5
    Member
    Join Date
    Jul 2009
    Posts
    11

    Default

    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. #6
    Member
    Join Date
    Jul 2009
    Posts
    11

    Default

    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. #7
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by isandell View Post
    In case anyone else is looking to do this, this is what worked for me.

    Quick and dirty

    <?php
    $file = file_get_contents ('http://usernameassword@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.
    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-...ss-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. #8
    Member
    Join Date
    Jul 2009
    Posts
    11

    Default

    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. #9
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by isandell View Post
    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?
    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.

    Quote Originally Posted by isandell View Post
    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
    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. #10
    Member
    Join Date
    Jul 2009
    Posts
    11

    Default

    Quote Originally Posted by cPanelDavidG View Post
    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.
    Sort of understand that. When is a new version of cPanel likely to be released, months or years?

    Quote Originally Posted by cPanelDavidG View Post
    So far we have $xmlapi->api2_query($cPanelUser, 'Email', 'listforwards')

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

    Missing argument 4 for xmlapi::api2_query()

    Any ideas?

    Thanks

    Ian

  11. #11
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by isandell View Post
    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
    The forth parameter is an associative array, so you would pass in array(domain => 'example.com') where example.com is your domain.

Similar Threads & Tags
Similar threads

  1. Email filters to take effect before the email forwarders
    By jpratt in forum Feature Requests for cPanel/WHM
    Replies: 0
    Last Post: 01-21-2011, 10:41 AM
  2. Log Listing Of Email Space Used
    By secureID in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 02-01-2005, 07:58 AM
  3. [WHM] Email Relayer Listing Problem
    By PPNSteve in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 09-14-2004, 05:57 PM
  4. Email forwarders
    By nost in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 12-04-2002, 01:12 PM
  5. Email Forwarders
    By SharonM in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 11-07-2002, 04:30 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube