A
A
alesto2014-11-08 18:09:31
C++ / C#
alesto, 2014-11-08 18:09:31

How to delete messages from the mailbox using imap4 in c#?

Good day. I need to get all unread emails via imap4. This is easy to understand, I use MailSystem.NET for this. But there is a problem with removal. I understand that in order not to accidentally bang a new letter, you need to use their UID , but I can’t get it. There is some messageID but it is String. Uid is an int and there is simply nothing of the kind in the message type objects received from the mailbox.
Can you please tell me how to get the uid for deleting emails? Or how to use the position of the letter on the server so as not to delete unnecessary ones? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alesto, 2014-11-09
@alesto

In general, I myself found the answer, although it took quite a long time to google.
Mailbox inbox = imap.SelectMailbox("inbox"); // get directory
int[] ids = inbox.Search("UNSEEN"); //get the id of unseen messages
To get the uid of the message, use the id on the server
inbox.Fetch.Uid(id);
To delete a message using uid
inbox.UidDeleteMessage(uid, true);
This is not finished code. But I would do this
1) Collect all the uids that we need to remove.
2) Then would delete all message in a cycle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question