MailItem.HtmlBody引发未实现的异常 [英] MailItem.HtmlBody throws a Not Implemented exception

查看:241
本文介绍了MailItem.HtmlBody引发未实现的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能区按钮,可通过根据其中的收件人修改MailItem对象将文本插入到Outlook Inspector中.点击时调用的方法如下:

I have a ribbon button that inserts text into an outlook Inspector by modifying the MailItem object based on the recipients in it. The method that gets called on click looks like this:

public async void OnTemplateClick(Office.IRibbonControl control)
        {
            var templateId = control.Tag;
            var template = templates.GetTemplateById(templateId);
            await templateUi.SetTemplate(control.Context, template);
        }

SetTemplate方法如下:

the SetTemplate method looks like this:

public async Task SetTemplate(object window, Template template, 
            SynchronizationContext uiThread = null)
{
Outlook.MailItem currentMailItem = null;
            Outlook.Recipients olRecps = null;
            Outlook.Recipient recp = null;
            Outlook.AddressEntry addEntry = null;
            try
            {
                currentMailItem = GetMailItem(window);
                olRecps = currentMailItem.Recipients;
                var recipType = Outlook.OlMailRecipientType.olTo;
                var recps = from r in olRecps.Cast<Outlook.Recipient>()
                            where r.Type == (int)recipType
                            select r;
                var numRecps = recps.Count();

                var oldBodyHtml = currentMailItem.HTMLBody;
               ...

现在,有时,获取HTMLBody的最后一行会引发以下错误:

Now, sometimes, that last line that fetches the HTMLBody throws the following error:

System.Runtime.InteropServices.COMException (0x8E604001): Not implemented.
   at Microsoft.Office.Interop.Outlook._MailItem.get_HTMLBody()

该错误不会一直发生,并且很难重现,因此我们通常会在应用程序日志中看到它.我想知道什么可能导致此错误?我认为这与异步调用的时间有关,这意味着MailItem消息没有完全形成吗?

This error doesnt happen all the time and its very difficult to reproduce so we mostly see it in the application logs. I was wondering what could possibly be causing this error? I assumed this has something to do with the timing of this asynchronous call which means that the MailItem message isnt fully formed?

谢谢!

推荐答案

Outlook对象模型不能在辅助线程上使用. Outlook 2016在检测到此类呼叫时将立即引发错误.在旧版本的Outlook中,呼叫可能会意外失败.

Outlook Object Model cannot be used on a secondary thread. Outlook 2016 will raise an error immediately as it detects such a call. In the older versions of Outlook the calls can fail unpredictably.

如果必须使用辅助线程,则唯一的选择是扩展的MAPI (C ++或Delphi)或兑换(其 RDO 对象族

If secondary thread is a must, your only options are Extended MAPI (C++ or Delphi) or Redemption (its RDO family of objects can be used on secondary threads).

这篇关于MailItem.HtmlBody引发未实现的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆