我正在尝试使用 libcurl 从 IMAP 服务器检索消息。这是我从在线示例中使用的代码:
#include <stdio.h>
#include <curl/curl.h>
int main(void){
CURL *curl;
CURLcode res = CURLE_OK;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
return (int)res;
}
不幸的是,这不起作用。我得到以下输出:
C SELECT INBOX/;UID=1
< C NO Mailbox doesn't exist: INBOX.;UID=1
* Select failed
如果不是
curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1");
我只放了curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX);
然后我实际上得到了关于收件箱的有用输出,就像我应该做的那样,没有错误。我在 ubuntu 上用 gcc 编译。
最佳答案
只为那些在这段时间之后阅读这篇文章的人
如果我输入 Google Mail 帐户,该代码将为我运行。像这样:
curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.gmail.com:993/INBOX/;UID=1");
(使用 gcc 在 ubuntu 中编译)
关于ubuntu - 如何使用 libcurl 和 C : 从 IMAP 服务器读取消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21295286/