Soporte para el comando IMAP IDLE
Contents
[
Hide
]
La API Aspoe.Email ImapClient proporciona la capacidad de abrir una conexión con el servidor y esperar la llegada de un mensaje de correo electrónico. Esto permite evitar consultar al servidor una y otra vez por cualquier correo electrónico entrante. El siguiente fragmento de código muestra cómo proporcionar soporte para el 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); |