2
votes

I have a Windows service using the AE.Net.Mail IMAP client with G-mail. The service runs every x minutes, retrieves inbox messages, applies some business logic, and marks them as deleted. This all works.

However, Gmail leaves them in the inbox so subsequent calls fetch them again. I can skip them by looking at the Seen or Deleted flags but I'd rather not get them at all. Unless someone goes in and cleans up the inbox frequently fetches will grow exponentially.

I've experimented with Gmails expunge options but they don't seem to have any effect.

3
I think emails have unique ID as well. You could try saving the ID and then only fetch the emails that do not have the ID... Not really an elegant solution. btw, there is a DeleteMessage method in the ImapClient class - jao
Thanks. Yes the DeleteMessage method successfully adds a Deleted flag to the message. Gmail doesn't delete it though; it remains in the inbox as a read message. - Sirentec

3 Answers

4
votes

I know this is a bit old post but just in case anybody is looking for a way to do this can try :

ImapClient ic = new ImapClient("imap.gmail.com", "[email protected]", "pass", AuthMethods.Login, 993, true);
var mailMessage = ic.SearchMessages(SearchCondition.Unseen(), false, true).ToList();

Now you can loop through the mailMessage for unread email.

2
votes

I decided to just filter them out when I retrieved them. Not ideal, but it works

 List<AE.Net.Mail.MailMessage> mm = _client.GetMessages(0, 10, false, false)
                                            .Where(m => !m.Flags.HasFlag(Flags.Seen) 
                                                   && !m.Flags.HasFlag(Flags.Deleted)).ToList();
0
votes

I know this is a bit old post but just in case anybody is looking for a way to do this can try move:

AE.Net.Mail.Imap.Mailbox[] mailBoxes = client.ListMailboxes(string.Empty, "*");
                        bool existeMailBoxArquivo = false; 
const string ARQUIVO = "ARQUIVO";

                        foreach (var mailBox in mailBoxes)
                        {
                            if (mailBox.Name == ARQUIVO)
                                existeMailBoxArquivo = true;
                        }
                        if (!existeMailBoxArquivo)
                            client.CreateMailbox(ARQUIVO);
                        client.MoveMessage(msg.Uid, ARQUIVO);

So you move the messages to a file folder, and when you browse again, just select the main box to search