Thursday, September 4, 2008

Avoiding multiple password prompt for IMAPISession::OpenMsgStore

If you have a multi threaded application and you login to the same profile from multiple threads to do some work, you may be prompted again and again for the password while calling IMAPISession::OpenMsgStore for password protected PST file or exchange mailbox.

Lets say your main thread login to the MAPI and open a password protected PST file (The user was prompted for the password). After processing you close the message store (not logging off from the session). Now if some other thread again opens the same PST file, the user will be presented with the password prompt again.

To avoid this is, on you main thread, don't release the IMsgStore pointer until you log off from the session. If you do so, then on other threads, although you will be creating a new MAPI session, you will not prompt for the password

I had a similar issue in which user was prompted for the password twice for the same PST, which was solved by this trick.

1 comment:

IMIBO said...

What if you just use flag MAPI_ALLOW_OTHERS inside MAPILogonEx ???