受信者に基づいて MailItem オブジェクトを変更することにより、Outlook インスペクターにテキストを挿入するリボン ボタンがあります。クリック時に呼び出されるメソッドは次のようになります。
public async void OnTemplateClick(Office.IRibbonControl control)
{
var templateId = control.Tag;
var template = templates.GetTemplateById(templateId);
await templateUi.SetTemplate(control.Context, template);
}
SetTemplate メソッドは次のようになります。
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 をフェッチする最後の行で次のエラーがスローされることがあります。
System.Runtime.InteropServices.COMException (0x8E604001): Not implemented.
at Microsoft.Office.Interop.Outlook._MailItem.get_HTMLBody()
このエラーは常に発生するわけではなく、再現が非常に難しいため、ほとんどの場合、アプリケーション ログに表示されます。このエラーの原因は何だろうかと考えていました。これは、MailItem メッセージが完全に形成されていないことを意味する、この非同期呼び出しのタイミングと関係があると思いましたか?
ありがとう!