+1 vote

Hi, I am trying out the Mail.dll for our project which periodically (say, every 1 minute) checks the inbox, handles any emails found, then wait for the next timer tick.

So, my question is what the best practice is to use this Imap object: should I use a single memberwise object to keep one connection and do all the mail-related work or like your sample codes that always dispose it after each use.

using(Imap imap = new Imap())
{
    imap.Connect("imap.server.com");       // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");
    imap.SelectInbox();
    imap.Close();
}

Thanks.

by (250 points)
edited by

1 Answer

0 votes

1.
You can't use the Imap instance after it's disposed.
So if you plan pooling, you should recreate Imap object every time.

The object creation doesn't cost much - it's the connecting and logging-in that takes some time (more likely seconds than minutes).

2.
You may want to check out IMAP IDLE to get instant message notifications:
https://www.limilabs.com/blog/imap-idle

by (297k points)
Thank you for your answer. I will go with your (1) then.
...