Page 1 of 1

I can't used php for get all message in mail account as json from vesta cp

Posted: Wed Aug 24, 2022 11:26 am
by wavesico
I used to php for get all massage in mail account as json from vesta cp but don't work it. How can I fix it ?

Code: Select all

<?php
// Server credentials
$vst_hostname = 'cordrr.tk';
$vst_username = 'admin';
$vst_password = 'YwoKFVYeNj';
$vst_command = 'v-list-mail-account';

// Account
$username = '[email protected]';
$domain = 'cordrr.tk';
$format = 'json';

// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'cmd' => $vst_command,
    'arg1' => $username,
    'arg2' => $domain,
    'arg3' => $format
);
$postdata = http_build_query($postvars);

// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);

// Parse JSON output
$data = json_decode($answer, true);

// Print result
print_r($data);

?>
and other way by imap_open

Code: Select all

<?php

    $imap = imap_open("{cordrr.tk:143/imap/tls}INBOX", "[email protected]", "admin");
    $headers = imap_headers($imap);

    if (!$headers) {
        print "Failed to retrieve headers\n";
    } else {
        foreach($headers as $header) {
            print "$header\n";
        }
    }

    imap_close($imap);
?>
Notice: Unknown: Can't connect to sev.cordrr.tk,143: Timed out (errflg=2) in Unknown on line 0