Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need help to delete a mail message based on some condition in c#.

i found something like below on some search on internet-

imap.Command("copy " + ids[i].ToString() + " [Gmail]/" + action_flag);

this seems to be copying it to some folder, not delete.

Is there any way to delete the message using message id. my code is-

MessageCollection idsDel = inbox.SearchParse("SEEN BEFORE " + dtDeletebeforeDate + " FROM GOURAV");

int[] ids = inbox.Search("SEEN BEFORE " + dtDeletebeforeDate + " FROM GOURAV");

C#
if (idsDel.Count > 0)
                       {

                           Message msg = null;

                           for (var i = 0; i < idsDel.Count; i++)
                           {
                               msg = inbox.Fetch.MessageObject(ids[i]);
                               if (msg.MessageId == idsDel[i].MessageId)
                               {
                                   imap.Command(


                                   break;
                               }
                           }


                       }



is there any way to use something in command directly to delete the message?
Posted

1 solution

You have to store the message, and the call expunge.
The store command looks like:
C#
_CommandText = string.Format("{0} STORE {1} +FLAGS (\\DELETED)\r\n", CommandPrefix, sequenceNumber);

with CommandPrefix being the number of the call, and sequenceNumber the number of the mail message
The expunge command looks like:
C#
_CommandText = string.Format("{0} EXPUNGE\r\n", CommandPrefix);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900