私は現在、タイトルが示すように、gmail POP3 アカウントから電子メールを読み取ることができる必要がある C++ プロジェクトで作業しています。また、メールとその本文の添付ファイル (base64 でエンコードされていますか?) をダウンロードする必要があることも重要です。実際には、誰もがこのタスクに libCurl を使用することを推奨していますが、Web 上のコード サンプルは機能していません。私はLibcurlのウェブサイトでこの例を見ました:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
/* Set username and password */
curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
/* This will only fetch the message with ID "1" of the given mailbox */
curl_easy_setopt(curl, CURLOPT_URL, "pop3s://user@pop.example.com/1");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
ご覧のとおり、コードは受信トレイ内の電子メールごとに電子メールをフェッチするのは非常に簡単に見えますが、CURLcode curl_easy_perform(CURL *)で操作を実行しようとすると、関数は何も返さず、プロセスは「死ぬ」ので、できますこの行をスキップしてください。私のコードは次のとおりです。
void MailServer::Open(char *username,char *password)
{
m_username = username; //username = example@gmail.com
m_password = password; //password = blabla123
curl = curl_easy_init();
curl_easy_setopt(curl,CURLOPT_USERNAME,username);
curl_easy_setopt(curl,CURLOPT_PASSWORD,password);
m_popsAccount = "pop3s://" + m_username +"/1";
curl_easy_setopt(curl, CURLOPT_URL, m_popsAccount.c_str());
res = curl_easy_perform(curl); //here does not return anything
}
私はウェブ上で「明確な」例を見つけようとしましたが、本当にできませんでした.誰かが私に手を差し伸べてくれますか? :)