1

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.

Martin Törnwall
  • 9,299
  • 2
  • 28
  • 35
  • What the ShowCategoriesDialog method shows for the item in the Sent Items folder? – Eugene Astafiev Mar 24 '15 at 13:56
  • I accessed the categories dialog through the context menu for the sent items. They seem to have no categories applied. – Martin Törnwall Mar 24 '15 at 13:58
  • Is your outlook running on an Exchange Server that is older than 2013? There could be a rule in the server to strip the categories. If that's the case, this could help. http://www.slipstick.com/outlook/email/sending-categories-on-email-messages/ – Natzely Mar 24 '15 at 16:32
  • The account I've set up for testing is a simple Hotmail account; maybe that's where my categories get stripped? – Martin Törnwall Mar 24 '15 at 18:21

1 Answers1

1

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).

Sanjay Karia
  • 309
  • 1
  • 3
  • 13
  • I think the Message categories should not be dependent upon the Mail server. – Sanjay Karia Mar 25 '15 at 11:36
  • I was able to reproduce your result by connecting Outlook to GMail instead. It worked flawlessly, so my guess is that the Exchange server may have been stripping the categories as Natzely hinted at above. – Martin Törnwall Mar 25 '15 at 22:26