none
How to get EntryID of a SMIME message? RRS feed

  • Question

  • I am using following code to read the EntryID of the selected message in Outlook 2003.

    Outlook._Application OlApp = this.OutlookAppObj as Outlook._Application;
    Outlook.Selection Selection = OlApp.ActiveExplorer().Selection;
    if (Selection.Count == 1)
    {
    	object selectedItm = Selection[1];
    	Type itemType = selectedItm.GetType();
    	string messageClass = "";
    	string entryID = "";
    	Try	{
    		messageClass = (string)itemType.InvokeMember("MessageClass", 
    BindingFlags.GetProperty, null, selectedItm, new object[0] { });
    		entryID = (string)itemType.InvokeMember("EntryID", BindingFlags.GetProperty, 
    null, selectedItm, new object[0] { });
    	}
    	catch (Exception Ex)
    	{
    	}
    }

    I can read the messageClass for all the emails. But entryID is working only when messageClass is IPM.Note. When ever the messageClass is IPM.Note.SMIME, it throws an error when I try to read the entryID. How can I get EntryID of a SMIME email?

    Monday, December 9, 2013 3:25 PM

All replies

  • Hello Sameendra,

    First of all, why do you use the late binding technology? Instead you could wrote (a raw sketch):

    Outlook._Application OlApp = this.OutlookAppObj as Outlook._Application;
    Outlook.Explorer explorer = OlApp.ActiveExplorer();
    Outlook.Selection Selection = explorer.Selection;
    if (Selection.Count == 1)
    {
        object selectedItm = Selection[1];
        Outlook.MailItem mail = selectedItm as Outlook.MailItem;
        if(mail!=null)
        {
            try
            {        
                string messageClass = mail.MessageClass;
    	    string entryID = mail.EntryID;
                // or try to use the PropertyAccessor
                Outlook.PropertyAccessor prop = mail.PropertyAccessor;
                object entry = prop.getValue(..); 
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);   
            }
        }
        Marshal.ReleaseComObject(selectedItm);	
    }
    Marshal.ReleaseComObject(Selection);
    Marshal.ReleaseComObject(explorer);

    The MessageClass values contain the following description for the IPM.Note.SMIME:

    • The message is encrypted and can also be signed.

    In that case you can try to use the PropertyAccessor class for getting the PR_ENTRYID property. Does it help?

    Monday, December 9, 2013 5:18 PM
  • Hello Eugene,

    Thanks for the reply.

    I tried it but it is not working. Outlook.MailItem mail = selectedItm as Outlook.MailItem; always returns an empty object (null) for IPM.Note.SMIME items. Any idea why?

    Tuesday, December 10, 2013 7:22 AM
  • Hello Sameendra,

    In C# you can add a reference to Microsoft.VisualBasic and run the following code:

    MessageBox.Show(Microsoft.VisualBasic.Information.TypeName(selectedItm));
    
    What type name does it return?

    Tuesday, December 10, 2013 10:37 AM
  • Hello Eugene,

    The MessageBox shows "MailItem" but Outlook.MailItem mail = selectedItm as Outlook.MailItem still returns "null".

    Tuesday, December 10, 2013 11:13 AM
  • Hello Sameendra,

    That is strange... Outlook wraps an encrypted message into a regular mail item object. What error do you get when you run the following code?

    entryID = (string)itemType.InvokeMember("EntryID", BindingFlags.GetProperty, 
    null, selectedItm, new object[0] { });

    Also make sure that you install the latest updates and service packs for Office/Outlook.

    Did you try to use Extended MAPI for getting a property value?

    Wednesday, December 11, 2013 10:12 AM
  • Hello Eugene,

    All the latest Office/Outlook updates and service packs are installed.

    When I try to get the entryID, it throws "Ein Aufrufziel hat einen Ausnahmefehler verursacht" error.

    I didn't try Extended MAPI. Do you have a sample code for me?

    Thanks

    Thursday, December 12, 2013 11:13 AM