如何从Yandex Mail for Domain API导入邮箱

时间:2015-06-01 13:28:38

标签: php email curl yandex yandex-api

情况:

我将Yandex Mail for Domain API用于我的应用。
我正在使用php curl测试API的所有http请求。 除了两个功能外,一切都运行正常:

  • 导入单个邮箱
  • 导入多个邮箱

我不知道问题是与sintax有关还是与其他因素有关。

代码:

public function yandex_import_mailbox()
{
    $url ='https://pddimp.yandex.ru/api2/admin/import/start_one_import?domain=MY_DOMAIN.com&method=pop3&server=pop.yandex.ru&port=110&ssl=no&ext-login=NAME@MY_DOMAIN.com&ext-passwd=MY_PASSWORD&int-login=LOGIN_YANDEX_API&int-passwd=PASSWORD_YANDEX_API';

    $header = array("PddToken: MY_TOKEN");

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');

    $retValue = curl_exec($ch);
    $response = json_decode(curl_exec($ch));
    $ee       = curl_getinfo($ch);
    print_r($ee);

    print_r($retValue);
}

这是我得到的json:

{"domain": "MY_DOMAIN.com", "success": "error", "error": "empty_import_list"}



文档:

这是关于导入单个邮箱的文档链接。

https://tech.yandex.com/domain/doc/reference/import-start-one-docpage/



工作示例:

这是一个有效的http请求示例,其结果与此问题有关。该函数返回导入的状态。

public function yandex_get_import_status()
{
    $url = 'https://pddimp.yandex.ru/api2/admin/import/check_imports?domain=MY_DOMAIN.com';

    $header = array("PddToken: MY_TOKEN");

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');

    $retValue = curl_exec($ch);
    $response = json_decode(curl_exec($ch));
    $ee       = curl_getinfo($ch);
    print_r($ee);

    print_r($retValue);
}

这是json格式的输出:

{"import": {"on_page": 10, "complete_box_count": 0, "failed_boxes_current_page": 1, "total_box_count": 0, "done_box_count": 0, "state": "no_import", "failed_boxes_count": 0, "total_message_count": 0, "failed_boxes_pages": 0, "page": 1, "failed_boxes": []}, "domain": "MY_DOMAIN.com", "progress_percent": 0, "success": "ok", "settings": {"port": 0, "ssl": "yes", "method": "", "server": ""}}



问题:

如何正确地将http请求导入单个邮箱到Yandex Mail for Domain API?

0 个答案:

没有答案