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.
It worked for me on Outlook 2013 ( 64-bit ) with a Gmail account configured. i.e. I can see the categories applied at all the steps - viz., while applying the categories in Visual Studio 2013, in the Outbox and also in the Sent Items folder.
Possible reason - Some addin might be removing the categories in the Sent Item folder. try to disable other addin(s).