Programmatically deleting outlook.com pop3 emails via LibCurl

Stan Malachowski 51 Reputation points
2023-05-11T06:11:38.45+00:00

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;
	}
	else
	{
		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,

Stan

Outlook
Outlook
A family of Microsoft email and calendar products.
2,956 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Minxin Yu 10,031 Reputation points Microsoft Vendor
    2023-05-11T08:41:06.25+00:00

    Hi,

    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.

    1 person found this answer helpful.
    0 comments No comments

  2. Stan Malachowski 51 Reputation points
    2023-05-11T11:01:46.7133333+00:00

    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

    or

    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,

    Stan

    1 person found this answer helpful.

  3. Stan Malachowski 51 Reputation points
    2023-05-12T03:47:10.84+00:00

    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,

    Stan

    1 person found this answer helpful.