After you've completed your work, you need to release the MAPI session that you've been working with. If you don't or if your program terminates unexpectedly (which happens quite a lot during development), you'll reach MAPI's session limit. In that case, you'll receive a message indicating that you have too many current sessions and that you are unable to establish a new session.
MAPI Won't Allow An Infinite Number of Sessions
In order to clear MAPI sessions, if you have either the mail client or schedule plus running, you can select File, Exit and Log Off from their menus. This will effectively sign you off of MAPI and close all sessions.
In your program code, you can clear the MAPI session by calling the MAPILogoff API function. You simply pass in the session ID that you want to logoff from and MAPI will clear it, closing the connection and invalidating the session ID.
iStatus = MAPILogoff(gMAPISession, 0, 0, 0)
The status returned should again be SUCCESS_SUCCESS, although in almost all cases, it's not a status that you need to interpret for the user. This is mostly due to the fact that if the process fails, it probably means that the session ID is invalid, indicating that the connection has already been closed by another process. This can happen if, as indicated above, the user goes into Mail or Schedule Plus and Logs off the system from within those applications.