VS.NET 2010 (and above) Users Click Here   

HOMECONTACT PRODUCTS DOWNLOADS PURCHASE TESTIMONIALS FORUMS COMPANY CONTACT
Home
Products
Downloads
Purchase
Licensing
Licensing FAQ
Software Updates
Support Forums
Testimonials
Feature Requests
Guarantee
About Us
Contact Us
Hosting Companies
Privacy Policy
   
Shopping Cart


Feature Requests forum

Name  
Email*  
Subject  
Message
 
 
Protected by Clearscreen.SharpHIPTo prevent abuse from bots, please enter the text you see.:
 

Original Post
From: "dave wanta" <dave@...>
Date: 4/10/2013 12:04:04 PM
Subject: RE: Way to periodically query for new messages
Hi Mike,
Sure:

ManualResetEvent idleWatcher = new ManualResetEvent(false);
void IMAPIdleTest()
{
	IMAP4 imap = new IMAP4( true, false);

	//create and load the ssl socket
	AdvancedIntellect.Ssl.SslSocket ssl = new AdvancedIntellect.Ssl.SslSocket();
	imap.LoadSslSocket( ssl );


	//rest of the IMAP properties
	imap.Port = 993;
	imap.Connect();
	imap.Login();


	MailFolderCollection mfc = imap.FolderList();

	//get the message count
	MailFolder inbox = imap.SelectInbox();

	//wire up the idle event
	inbox.IdleResponse += new IdleResponseEventHandler( OnIdleResponse );

	Console.WriteLine("starting to idle...");

	inbox.Idle();
	
	while( idleWatcher.WaitOne() )
	{
		//our idleWatcher notified us of new messages.
		break;
	}
	


	inbox.IdleStop();

	//get the latest messges that just came in
	string recentSet = inbox.SearchClient.RecentSet();

	if( ( recentSet != null ) && ( recentSet.Trim().Length > 0 ) )
	{
		//download the latest
		MimePartCollection messages = inbox.FetchClient.Messages( recentSet,IndexType.UniqueId, true );

		//loop through the messages, and write out the subject
		foreach( MimeMessage message in messages)
		{
			if( message != null )
			{
				if( message.Subject != null )
				{
					Console.WriteLine( message.Subject.Value );
				}
				else
				{
					Console.WriteLine( "No subject");
				}
			}
		}

	}

	imap.Disconnect();

}
void OnIdleResponse( object sender, IdleResponseEventArgs e )
{
	//write out the response sent from the server
	string response = System.Text.Encoding.ASCII.GetString( e.Data, 0, e.DataCount );
	Console.WriteLine( response );

	//in here, we could open a new IMAP connection to download the latets messages
	//IMAP4 imap = new IMAP4();
	//iimap....

	//or we could notify the waiting thread, that we received and update, and the waiting thread, could continue processing.
	//One way of doing this, is by using a ManualResetEvent
	idleWatcher.Set();
}




Does that help?
--Dave

 

 

 




To post a code snippet, please enclose the code in [code] [/code] blocks. For example
[code]
EmailMessage = new EmailMessage();
m.To = "test@test.com";
[/code]

* In order to reduce SPAM BOTS from harvesting email addresses, only the alias part of the email address will be shown.
For example: 'test@test.com' will become 'test@...'.

We are requiring the address, in case we would like to contact you privately about your situation. However, if you still don't feel comfortable submitting it, you can always use 'bob@example.com' ;-)


 

 

Testimonial

We're using the new imail secure server 2006 version and have written a .NET script to send out personalized newsletters to our customers. We are able to compose 5,000 personalized newsletters a minute with unique tracking links and images using ASPNETEMAIL. Pretty impressive. "

B. Wire | Better Trades

Read more testimonials
ListNanny aspNetDNS aspNetEmail aspNetPOP3 aspNetMX IPMuncher aspNetMIME aspNetPING aspNetTraceRoute aspNetIMAP aspNetMHT