Listing e-mails trough API

smiegt

Verified User
Joined
Oct 29, 2009
Messages
7
Hi Guys,

I've been bugging myself for more than a week now trying to do a relative simple thing , (at least i tought it would be). I need to produce a list of all active e-mail adresses on my DA machine to hand over to the Dutch District of Justice daily.

I'm trying to do a user listing, then list domains per user then list e-mails per domain. That wouldn't work for me , so i tried it simpler which also didn't work.

I kept getting the following error :

Array ( [error] => 1 [text] => Could not excute your request [details] => You do not own that domain )

Thats a printout from the fetch_parsed_body() method which i use to capture the output.


I've tried to print a list of users trough the API which worked without problems, but when i try to print a list of e-mails per domain it always gives the above error.

Following is my code, don't pay attention to the messy layout because i've been testing some theories to get it to work.


function getemldata(){

$sock = new HTTPSocket;
$sock->connect("myhost.nl",2222);
$sock->set_method('GET');
$sock->set_login("admin","mykickasspassword");
$sock->query('/CMD_API_POP','domain=mytestdomain.nl&action=list');
$row = $sock->fetch_parsed_body();
print $row;
print_r($row);
print $row[0];
if(empty($row['list'])){
echo 'Lege domeinen lijst<br>';
echo "".$row['text'];
echo $row;
echo "".$row['details'];
if($row['error']= 1){
echo "error ding";
}
}else{
echo '<table><tr><th>Email adress</th></tr>';
for($i = 0;!empty($row['list'][$i]);$i++){
echo '<tr><td>'.$row['list'][$i].'</td></tr>';
}
echo '</table>';
}


The code always ends in the error if so prints it.
The print_r method gives me the error as i posted above (not owned domain).

I hope someone knows why the heck this wont work

Thanks in Advance,

Greetz,

Smiegt
 
Hello,

I took your code and changed it a bit. Your socket code was correct. I didn't bother with your tables though, but my output is simple. Adjust to your needs. I did test this and it worked fine for me.
Code:
<?

include("httpsocket.php");

$domain="yourdomain.com";
$user="admin";
$pass="yoursuperpassword";

$sock = new HTTPSocket;
$sock->connect("127.0.0.1",2222);
$sock->set_method('GET');
$sock->set_login($user, $pass);
$sock->query('/CMD_API_POP',"domain=$domain&action=list");

$a = explode('&', $sock->fetch_body());
$values = Array();

$i=0;
foreach ($a as $v)
{
     $values[$i++] = substr(strstr($v, '='), 1);
}

foreach ($values as $email)
{
        echo "Email: ".$email."@".$domain."<br>\n";
}

?>
Related guide:
http://help.directadmin.com/item.php?id=204

John
 
Hello,

I took your code and changed it a bit. Your socket code was correct. I didn't bother with your tables though, but my output is simple. Adjust to your needs. I did test this and it worked fine for me.
Code:
<?

include("httpsocket.php");

$domain="yourdomain.com";
$user="admin";
$pass="yoursuperpassword";

$sock = new HTTPSocket;
$sock->connect("127.0.0.1",2222);
$sock->set_method('GET');
$sock->set_login($user, $pass);
$sock->query('/CMD_API_POP',"domain=$domain&action=list");

$a = explode('&', $sock->fetch_body());
$values = Array();

$i=0;
foreach ($a as $v)
{
     $values[$i++] = substr(strstr($v, '='), 1);
}

foreach ($values as $email)
{
        echo "Email: ".$email."@".$domain."<br>\n";
}

?>
Related guide:
http://help.directadmin.com/item.php?id=204

John

Thanks for your reply John,

Only i keep getting the same error as before :

Array ( [0] => error=1 [1] => text=Could not excute your request [2] => details=You do not own that domain ) Email: [email protected]
Email: Could not excute your [email protected]
Email: You do not own that [email protected]


I login as admin, and i guess there's the problem?
 
Who *does* own the domain? Say for example, it's user "fred". If you want to get the email accounts for fred's domain called "freddomain.com".. but you only have the admin password, then you'd use:

$user = "admin|fred";
$pass = "adminspass";

and the API would be logged as as fred, using admin's password (since admin has control over fred). This is the exact same way the "Login as fred" button works when viewing fred's data. You can also type that user/pass combo into the normal DA login screen in your browser to login as fred (FYI).

John
 
You are my hero!

I tested that and it works!! only thing I now need to do is make a nice script that loops al users through there!!

Thanks alot John!

Greetz,

Bram
 
Back
Top