I've followed this tutorial to create a Custome Task Pane when composing a new message: https://learn.microsoft.com/en-us/visualstudio/vsto/walkthrough-displaying-custom-task-panes-with-e-mail-messages-in-outlook?view=vs-2022&tabs=csharp
So far, it's working great. I push a button on the task pane & it fills in the BCC field on the message.
The probable is if someone opens more than one compose window, then the BCC only gets added to the most recently opened window. If I push the button on the previously opened compose window, then nothing happens.
I was doing this:
Globals.ThisAddIn.CurrentMailItem.BCC = "test@acb.com";
But the CurrentMailItem is no longer correct when switching back to the first compose window.
I tried this:
foreach (Inspector inspector in Globals.ThisAddIn.inspectors)
{
if (inspector.CurrentItem is MailItem)
{
MailItem mailItem = inspector.CurrentItem as MailItem;
mailItem.BCC = "test";
}
}
And it was able to add the BCC to both compose windows, but that's not what I want. How can I add the BCC to the current mailItlem of the clicked on task pane?