Is it possible to add different items to a mail item custom context menu by inspecting the contents of the item?
For instance, only add the item if the subject line contains "IMPORTANT".
views:
22answers:
1
+2
Q:
VSTO Outlook: Creating a dynamic custom context menu for a mail item determined by subject line
A:
This seems to work.
void Application_ItemContextMenuDisplay(Office.CommandBar CommandBar, Outlook.Selection Selection)
{
foreach (Outlook.MailItem m in Selection)
{
if (m.Subject.Contains("IMPORTANT"))
{
DeliveryFailureButton(CommandBar, Selection);
break;
}
}
}
void DeliveryFailureButton(Office.CommandBar CommandBar, Outlook.Selection Selection)
{
Office.CommandBarButton btn = CommandBar.Controls.Add(
Office.MsoControlType.msoControlButton,
missing, missing, missing, true) as
Office.CommandBarButton;
btn.Caption = "Move to IMPORTANT messages";
btn.Click += (Office.CommandBarButton Ctrl, ref bool CancelDefault) =>
{
string msg = "CRM Records\r\n";
foreach (Outlook.MailItem item in Selection)
{
if (item is Outlook.MailItem)
{
var mitem = item as Outlook.MailItem;
msg += "\r\n" + MoveToImportant(mitem);
}
}
MessageBox.Show(msg);
};
}
Kenneth J
2010-10-12 15:45:24