Getting StartedUsing the InterIMAP library is pretty straight forward. Just add a reference to InterIMAP.dll in your project, and you are ready to go.
Connectingusing InterIMAP;
IMAPConfig config = new IMAPConfig("server","username","password", ssl (true | false), autlogin (true | false), "initial folder");
IMAPAsyncClient client = new IMAPAsyncClient(config, 5); // 5 represents the number of worker connections to create. Depending on your bandwidth this number might need to be adjusted for optimal performance
client.Start();
The client is now connected and awaiting requests. The first request that should be done is the
FolderTreeRequest. This request will retrieve the list of folders in the account and generate the necessary
IFolders for them. This is accomplished by executing this:
client.RequestManager.SubmitRequest(new FolderTreeRequest("\"\"", FolderTreeCallback), false);
private void FolderTreeCallback(IRequest req)
{
// whatever logic you need to do to indicate the process has completed.
}
An alternative to using .SubmitRequest is to use SubmitAndWait, which will block the calling thread while the request executes. Be careful when using this method in applications that have a user interface as this will prevent the user from interacting with anything while the request is running.
Getting MessagesOnce you have the folder tree populated, the next step is to execute the
PopulateFolderData method which examines each folder and determines how many messages it contains and stores each message's UID. Once this is done, you are ready to start pulling down messages and examining their contents.
The most common operation is checking for new messages, which can easily be accomplished using the
NewMessageRequest object like this:
NewMessageRequest nmr = new NewMessageRequest(client);
nmr.NewMessageRequestCompleted += new NewMessageRequestCompletedHandler(new_messages);
nmr.Start(); // checks for new messages in all folders
IFolder folder = client.MailboxManager.GetFolderByPath("INBOX");
nmr.Start(folder); // checks for new messages in the INBOX folder only
private void new_messages(IMessage[] msgs)
{
// do what you need to do here
}