Hi there,
I am trying to delete emails via POP3 from an Outlook mailbox programmatically. I am using a C++ application with lib curl as the underlying , toolset.
Without going into huge detail, the segment of code is :
bool succeed(true);
stringstream ustr;
string res;
ustr << m_MailPOP3Url << "/" << num;
curl_easy_setopt(m_Curl, CURLOPT_URL, ustr.str().c_str());
curl_easy_setopt(m_Curl, CURLOPT_CUSTOMREQUEST, "DELETE");
/* Do not perform a transfer as DELE returns no data */
curl_easy_setopt(m_Curl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(m_Curl, CURLOPT_URL, ustr.str().c_str());
/* Perform the custom request */
res = curl_easy_perform(m_Curl);
if (m_CurlResult != CURLE_OK)
cerr << "Unable to delete mail number : " << num << endl;
succeed = false;
cout << "Deleted mail number : " << num << endl;
The active command is the "DELETE". This works against a gmail mail box, but the call against an Outlook folder comes back with an OK, but the message is still there. My process runs in a loop, so it starts at the top again and sees everything in the mail list once again.
Thanks for anyone's suggestion.
Regards,
To delete the email in outlook,
Use "DELE Num". E.g.
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELE 1");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELE 1");
/* Do not perform a transfer as DELE returns no data */
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
/* Perform the custom request */
res = curl_easy_perform(curl);
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thanks Minxin,
I had already tried this, and it did not work. Also, should the mail item number be at the end of the URL? For example if the mail item is 1, should the curl URL be:
pop3s://outlook.office365.com:995
pop3s://outlook.office365.com:995/1
I use the latter for gmail with "DELETE" and its fine. I have also checked that I have set the Outlook mailbox to allow the deletion of POP messages by clients.
Thanks,
Traces.pdfHi Minxin,
I have tried exactly that. Howver, it still fails to delete. What's more frustrating is that the curl.exe that I built when I compiled the library does delete the mail item. I have attached a document that has the two traces. The first is from the program, and the second is from cURL. Both traces report that the item is deleted (with a +OK). All I can imagine is that I am doing something strange in the initialisation. Could you please send me your initialization steps for curl?
Thanks,
if (curl) {
/* Set username and password */
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_USERNAME, "");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "");
/* You can specify the message either in the URL or DELE command */
curl_easy_setopt(curl, CURLOPT_URL, "pop3s://outlook.office365.com:995");
/* Set the DELE command */
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELE 1");
/* Do not perform a transfer as DELE returns no data */
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
/* Perform the custom request */
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 (int)res;
Hi Minxin,
I located the problem. The code I had previous works if I remove one line from my initialisation:
curl_easy_setopt(curl,CURLOPTTIMEOUT,1000);
I have had this line in place for some time, so it's possibly something being added to the header incompatible with the DELE command. I tried several values for the timeout and it makes no difference. The behaviour on a Gmail mailbox is not sensitive to this, so it would seem to be some sort of defect on the cURL side(?).
Thanks for your help,
Regards,