Close item

R

Richard Elgert

I am trying to open/read all email in the inbox.. (trying to delete duplicates)

Get error at 250th item sayin the system settings do not allow any more open than that

have this in code
' need to close the email
oMsg.Close(OlInspectorClose.olSave)

but does not close the mail item

how do I close properly so no error


Submitted using http://www.outlookforums.com
 
K

Ken Slovak - [MVP - Outlook]

Managed code with Exchange mailbox? That's the RPC channel limit, unless the
object reference is released that error will result after about 250 or so
operations.

Set the object to null each pass through the code, if necessary also call
Marshal.ReleaseComObject() on it and GC.Collect(). That will release all
those RPC channels that otherwise wouldn't be released until the procedure
ended and the objects went out of scope.

Also don't use concatenated dot operators:

string body = olApp.ActiveInspector.CurrentItem.Body;

Set up a variable for each dot operator so you can explicitly release
things. Otherwise intrinsic variables are created internally and you cannot
release those:

Outlook.Inspector insp = olApp.ActiveInspector;
Outlook.MailItem item = (Outlook.MailItem)insp.CurrentItem;
string body = item.Body;
 
R

Richard Elgert

retValue = System.Runtime.InteropServices.Marshal.ReleaseComObject(oMsg )
GC.Collect()

OK I did add the above 2 lines and the 250 limit error is gone.... but I am not sure I fully understand... (will your book clarify)

and a follow up, I need to browse all folders and sub-folders in a users mailbox. .
Submitted using http://www.outlookforums.com
 
K

Ken Slovak - [MVP - Outlook]

My book might mention the RPC limit but it's strictly an Exchange setting
that's controlled by a registry setting on the server. It limits how many
RPC channels any application can open at any one time so as not to bog down
the server. Since the setting can be anything if the admins change the
default, all you really need to understand is to follow best practices and
release your objects as soon as they are not needed and not to create
intrinsic object variables by using compound dot operators, especially
within loops where the objects will persist until the procedure running the
loop has ended.

I don't understand your question about folder browsing. Just use a recursive
procedure that digs into each MAPIFolder.Folders collection, starting with
the NameSpace.Folders collection or at a selected starting point.
 
R

Richard Elgert

Well to make a long story short... the whole purpose of this exercise was to delete duplicate emails... from several import of lotus Notes int Outlook, we wound up with hundreds of dupes. Tried the 'ODIR' recommended program, but that did not delete them... my code test showed that they all had a unique record ID.
Bought "Duplicate Email Remover" for $30 dollars and that did the job just fine...
I will work on my code when time permits....
Submitted using http://www.outlookforums.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top