Support for IMAP IDLE Command
Contents
[
Hide
]
Aspoe.Email API’s ImapClient provides the capability to open a connection to the server and wait for the arrival of an email message. This allows avoiding polling the server again and again for any incoming email. The following code snippet shows you how to Support for IMAP Idle Command.
This file contains hidden or 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); |