简体   繁体   中英

C# Limit Error when requesting E-Mails using MAPI

Always when I request E-Mails from my Outlook, which uses Office365 a COM-Exception is thrown, after a count of mails. I really have no idea why...

Error:

System.Runtime.InteropServices.COMException (0xBFE40305):
Die Anzahl der Elemente, die gleichzeitig geöffnet werden können, wurde vom Serveradministrator begrenzt. 
Schließen Sie zunächst geöffnete Nachrichten, oder entfernen Sie Anhänge und Bilder von 
ungesendeten Nachrichten, die Sie gerade verfassen.

   bei Microsoft.Office.Interop.Outlook._MailItem.get_Recipients()
.....

For the people that don't speak German, it means: The count of the elements which could be opened at the same time, is limited by the server administrator (....)

I don't know anything about such a Limit, and the solution which I can find on Google or MSDN don't help ether.

It looks like it crashes when the program tries to get the E-Mail recipients. Here is the way, how I try to get the Recipients:

                    foreach (var item in SelectedFolder.Items.Restrict(filter))
                {
                    Outlook.MailItem mail = item as Outlook.MailItem;
                    if (mail != null)
                    {
                        if (mail.Recipients.Count > 0)
                        {
                            string caption = mail.Subject;
                            string MAIL = mail.Recipients[1].PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E"); //<--- CRASH HERE
              

I really don't understand, how this can happen, as far I know, when I select E-Mails from Outlook, they just get "opened" local... So I can't get, how a "Server-Limit" can access to this.

In the online mode the number of simultaneously open objects is limited by the Exchange provider (since each object opens a separate RPC channel).

For the messages, the limit is 255 by default.

Do not use a foreach loop - it will keep each member of the loop referenced until the loop exits. Use a for loop and explicitly release the item (and all of its subjects that you retrieved, such as recipients or attachments) at the end of each iteration using Marshal.ReleaseComObject() . Avoid using multiple dot notation as that forces the compiler to create implicit variables that you cannot explicitly release.

Also keep in mind that the as operator also produces an implicit variable - break that line into two and release both variables using Marshal.ReleaseComObject()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM