简体   繁体   English

使用 MAPI 请求电子邮件时 C# 限制错误

[英]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.当我从使用 Office365 的 Outlook 请求电子邮件时,总是会在邮件计数后引发 COM 异常。 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.我对这样的限制一无所知,我可以在 Google 或 MSDN 上找到的解决方案对以太没有帮助。

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.我真的不明白,这怎么会发生,据我所知,当我从 Outlook 中选择电子邮件时,它们只是在本地“打开”......所以我无法理解“服务器限制”如何可以访问这个。

In the online mode the number of simultaneously open objects is limited by the Exchange provider (since each object opens a separate RPC channel).在联机模式下,同时打开的对象数量受 Exchange 提供程序的限制(因为每个对象都打开一个单独的 RPC 通道)。

For the messages, the limit is 255 by default.对于消息,默认限制为 255。

Do not use a foreach loop - it will keep each member of the loop referenced until the loop exits.不要使用foreach循环 - 它会一直引用循环的每个成员,直到循环退出。 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() .使用for循环并在每次迭代结束时使用Marshal.ReleaseComObject()显式释放项目(以及您检索的所有主题,例如收件人或附件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()还要记住, as运算符也会产生一个隐式变量 - 将该行分成两行并使用Marshal.ReleaseComObject()释放这两个变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于掩盖电子邮件的C#正则表达式 - C# Regex for masking E-Mails 使用 outlook api 打开电子邮件时引发错误 - Error thrown when opening e-mails using outlook api 如何修复错误“'的类型初始化程序?' 抛出异常。” 使用 EASendMail 通过 C# 发送电子邮件时? - How do I fix the error “The type initializer for '?' threw an exception.” when sending e-mails through C# with EASendMail? 如何使用 C# 查看前 20 个电子邮件 - How to see top 20 e-mails with C# C#使用microsoft.office.interop.excel在widndows表单上将电子邮件导出到excel - C# exporting e-mails to excel on widndows forms using microsoft.office.interop.excel 使用协议“ mapi://”从C#在Outlook中打开邮件 - Open mails in outlook from C# using the protocol “mapi://” 如何使用NLog发送电子邮件? - How to send e-mails using NLog? 没有默认凭据,ASP.Net C#应用程序不会发送电子邮件 - ASP.Net C# Application does not send e-mails without default credentials 将电子邮件拖放到指定的文件夹中,而不是通过SMTP服务器c#发送它们 - Drop e-mails into a specified folder instead of sending them via SMTP server c# 使用POP3从Outlook下载电子邮件接收服务器未找到错误 - Receiving Server Not Found Error using POP3 for downloading e-mails from Outlook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM