-2

I am trying to build code for recalling message in the outlook using c#. I have a customized tab in the outlook and have the button. I need to build a code on click of button(after selecting sent mail) , it has to call the recall message functionality of outlook.

I know the limitations for recalling messages. But still organization wants to continue with this. Let us know if anyone have c# code to the call the recall message button. Thanks and Regards,

Jyothi Srinivasa
  • 701
  • 2
  • 9
  • 26

2 Answers2

0

I have found the answer myself.

 1: private void btnRecall_Click(object sender, RibbonControlEventArgs e)
    2:        {
    3:            Outlook.MailItem oldMailItem = GetMailItem(e);
    4:            Inspector inspect=  oldMailItem.GetInspector;
    5:            inspect.Display(false);
    6:            inspect.CommandBars.ExecuteMso("RecallThisMessage");           
    7:        }
    8:
    9:    private Microsoft.Office.Interop.Outlook.MailItem GetMailItem(RibbonControlEventArgs e)
    10:        {
    11:            // Check to see if a item is select in explorer or we are in inspector.
    12:            if (e.Control.Context is Microsoft.Office.Interop.Outlook.Inspector)
    13:            {
    14:                Microsoft.Office.Interop.Outlook.Inspector inspector = (Microsoft.Office.Interop.Outlook.Inspector)e.Control.Context;
    15:
    16:                if (inspector.CurrentItem is Microsoft.Office.Interop.Outlook.MailItem)
    17:                {
    18:                    return inspector.CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;
    19:                }
    20:            }
    21:
    22:            if (e.Control.Context is Microsoft.Office.Interop.Outlook.Explorer)
    23:            {
    24:                Microsoft.Office.Interop.Outlook.Explorer explorer = (Microsoft.Office.Interop.Outlook.Explorer)e.Control.Context;
    25:
    26:                Microsoft.Office.Interop.Outlook.Selection selectedItems = explorer.Selection;
    27:                if (selectedItems.Count != 1)
    28:                {
    29:                    return null;
    30:                }
    31:
    32:                if (selectedItems[1] is Microsoft.Office.Interop.Outlook.MailItem)
    33:                {
    34:                    return selectedItems[1] as Microsoft.Office.Interop.Outlook.MailItem;
    35:                }
    36:            }
    37:
    38:            return null;
    39:        }
Jyothi Srinivasa
  • 701
  • 2
  • 9
  • 26
-1

how do I compile the below code in c# for outlook 2010 as command bar is depreciate and with IRibbonExtensibility

 Option Explicit Sub Recall()   Dim SendItem As Object   Dim olItem As
 Outlook.MailItem   Dim olInsp As Outlook.Inspector

   '// Selected item in Sent Items folder   Set SendItem =
 ActiveExplorer.Selection.Item(1)

  If TypeName(SendItem) = "MailItem" Then
     Set olItem = SendItem
     Set olInsp = olItem.GetInspector
     '// Execute Recall command button
     With olInsp
       .Display
       .CommandBars.FindControl(, 2511).Execute
       .Close olDiscard
     End With  

End If End Sub

/////My code looks as below

Outlook.MailItem MailItemRecall = (MailItem)selObject;
  if (MailItemRecall != null)
            {


                Outlook.Action recallaction = selObject.Actions.Add();
                recallaction.Name = "Recall This Message";
                recallaction.MessageClass = "IPM.Outlook.Recall";
                recallaction.ResponseStyle = OlActionResponseStyle.olSend;
                recallaction.CopyLike = OlActionCopyLike.olReplyFolder;
                recallaction.Execute(); 
}
Jyothi Srinivasa
  • 701
  • 2
  • 9
  • 26