I'm intercepting Outlook 2013's Application.ItemSend
event in order to manipulate the categories assigned to a MailItem
right before it's sent. Here's the event handler:
void Application_ItemSend(object Item, ref bool Cancel)
{
var mail = (Outlook.MailItem)Item;
mail.Categories = string.Join(";", "Foo", "Bar"); // Yes, the delimiter is ';' on my system.
mail.Save(); // Do I need this?
}
The problem is that the changes to the Categories
property don't seem to be properly persisted. When I view the message in the Sent folder, it appears uncategorized.
Curiously, if I call mail.ShowCategoriesDialog()
after changing the categories they appear checked as expected. This makes me suspect that I'm operating on a copy of the message.
What am I doing wrong?
It seems the issue was one of server configuration rather than my code. After connecting Outlook to GMail instead it worked as I expected.