ubuntu - 如何使用 libcurl 和 C : 从 IMAP 服务器读取消息

标签 ubuntu gcc curl imap libcurl

我正在尝试使用 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/

相关文章:

linux - 如何通过 svn post-commit hook 运行 svn update

c - 通过实现定义的宏识别 clang、gcc 和 tcc

足够困难地学习的 C 环境

php - 使用 PHP 的 PayPal curl 调用没有响应

mysql - docker mysql-server 没有在 ubuntu 上启动

ubuntu - VMware 错误 "Unable to change power state of virtual machine UPS: Operation inconsistent with current state"

ubuntu - 如何在 Ubuntu 中注册文件关联

c - 相同的 FLT_EVAL_METHOD,GCC/Clang 中的不同结果

powershell 相当于curl 命令

bash - 如何在文件中使用 curl 命令数据?