Suporte para o Comando IMAP IDLE
Contents
[
Hide
]
A API Aspose.Email ImapClient fornece a capacidade de abrir uma conexão com o servidor e aguardar a chegada de uma mensagem de email. Isso evita a necessidade de fazer polling no servidor repetidamente em busca de emails recebidos. O seguinte trecho de código mostra como Suportar o Comando IMAP Idle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Connect and log in to IMAP | |
ImapClient client = new ImapClient("imap.domain.com", "username", "password"); | |
ManualResetEvent manualResetEvent = new ManualResetEvent(false); | |
ImapMonitoringEventArgs eventArgs = null; | |
client.StartMonitoring(delegate(object sender, ImapMonitoringEventArgs e) | |
{ | |
eventArgs = e; | |
manualResetEvent.Set(); | |
}); | |
Thread.Sleep(2000); | |
SmtpClient smtpClient = new SmtpClient("exchange.aspose.com", "username", "password"); | |
smtpClient.Send(new MailMessage("from@aspose.com", "to@aspose.com", "EMAILNET-34875 - " + Guid.NewGuid(), "EMAILNET-34875 Support for IMAP idle command")); | |
manualResetEvent.WaitOne(10000); | |
manualResetEvent.Reset(); | |
Console.WriteLine(eventArgs.NewMessages.Length); | |
Console.WriteLine(eventArgs.DeletedMessages.Length); | |
client.StopMonitoring("Inbox"); | |
smtpClient.Send(new MailMessage("from@aspose.com", "to@aspose.com", "EMAILNET-34875 - " + Guid.NewGuid(), "EMAILNET-34875 Support for IMAP idle command")); | |
manualResetEvent.WaitOne(5000); |