Подключитесь к outlook.com почтовый сервер с PHP cURL


Я пытаюсь получить полный ответ с живого почтового сервера, используя php и curl. Я пытался подключиться по протоколу pop3, но он не работает.

Код-листинг 1:

<?php 
    // create curl resource 
    $curl = curl_init(); 

    if($curl) {
        /* Set username and password */ 
        curl_setopt($curl, CURLOPT_USERNAME, "[email protected]");
        curl_setopt($curl, CURLOPT_PASSWORD, "password");

        curl_setopt($curl, CURLOPT_URL, "pop3://pop3.live.com");
        curl_setopt($curl, CURLOPT_PORT, 995);

        curl_setopt($curl, CURLOPT_USE_SSL,CURLUSESSL_ALL);

        curl_setopt($curl, CURLOPT_CAINFO, "./certificate.pem");

        curl_setopt($curl, CURLOPT_VERBOSE, true);

        //return the transfer as a string 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

        // $output contains the output string 
        $output = curl_exec($curl);
    }

    echo $output;

    curl_close($curl); 
?>

Когда я использую этот код (с протоколом pop3). стандартный вывод сообщает мне, что клиент успешно подключился к порту 995. Но не может прочитать ответ.

Не удалось прочитать ответ

Закрытие соединения 0

Но когда я использую протокол https вместо pop3 (в том же коде) Я получаю частичный ответ. Это похоже на весь заголовок ответа, по крайней мере, так он выглядит, поскольку выводит две новые строки после последнего текста.

Принять: */*

Author: Paiku Han, 2016-07-03

1 answers

CURL имеет другой идентификатор протокола для безопасного POP по протоколу SSL.

Вместо pop3:// попробуйте pop3s://, и вы должны получить ответ обратно.

* Rebuilt URL to: pop3s://pop3.live.com/
* Hostname was NOT found in DNS cache
*   Trying 134.170.170.231...
* Connected to pop3.live.com (134.170.170.231) port 995 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES256-SHA
* Server certificate:
*    subject: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; CN=*.hotmail.com
*    start date: 2015-12-15 22:26:11 GMT
*    expire date: 2016-12-15 22:26:11 GMT
*    subjectAltName: pop3.live.com matched
*    issuer: C=BE; O=GlobalSign nv-sa; CN=GlobalSign Organization Validation CA - SHA256 - G2
*    SSL certificate verify ok.
< +OK DUB006-POP162 POP3 server ready
> CAPA
< -ERR unrecognized command
> USER me@xxx
< +OK password required
> PASS pass
< +OK Logged in.
> LIST
< +OK 5226 messages:
string(59927) "1 1830
2 69432
3 2751
4 2726
5 18506
6 2868
7 4636
8 1955
9 2242
10 3697
 1
Author: drew010, 2016-07-03 18:56:12