.net - Outlook.MailItem fails sometimes -


while iterating through email items, system cannot mail item same email item in next run. below sample of code using mail items.

        var oapplicationclass = new application();         namespace namespace = oapplicationclass.getnamespace("mapi");         outlook.mapifolder inbox = namespace.getdefaultfolder(oldefaultfolders.olfolderinbox);         outlook.mapifolder deleteditems = namespace.getdefaultfolder(oldefaultfolders.olfolderdeleteditems);          mailitem mailitem;           var safemail = new redemption.safemailitem();         items outlookitems = inbox.items.restrict("[messageclass] = \"ipm.note\"");         int totalcount = outlookitems.count;         string subject = "";         bool filtermessage = filters.count > 0;          if (totalcount > 0)         {             (int = 1; <= totalcount; i++)             {                 outlookitems.sort("[receivedtime]",                                   sortascending ? olsortorder.olascending : olsortorder.oldescending);                  try                 {                     mailitem = (mailitem) outlookitems[i];                     var testcount = mailitem.attachments.count;                     //code move email deleted items                 }                 catch (exception oex)                 {                     logger.debug("mail item cannot acquired, continuing other mail items.");                     logger.debug(oex.message);                     continue;                 }             }         } 

you need release all underlying com objects instantly. use system.runtime.interopservices.marshal.releasecomobject release outlook object when have finished using it. set variable nothing in visual basic (null in c#) release reference object.

this particularly important if add-in attempts enumerate more 256 outlook items in collection stored on microsoft exchange server. if not release these objects in timely manner, can reach limit imposed exchange on maximum number of items opened @ 1 time.

for example, can find sample code in how to: use restrict method retrieve outlook mail items folder article.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -