Reputation: 908
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.
Upvotes: 2
Views: 5411
Reputation: 13
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
Upvotes: 0
Reputation: 51
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.
Upvotes: 5
Reputation: 908
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();
Upvotes: 2