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);
}
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;
...
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()
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?
Thanks!