none
How to check if user has set a S/MIME certificate in Outlook 2013 (C#. VSTO 4. .Net 3.5) RRS feed

  • Question

  • Hi,

    we have a vsto addin and when the user tries to send an mail with smime encryption we check if the user has set an own certificate in the security settings in trust center. If not we show a dialog to the user and give some alternative possiblities.

    For Outlook 2007 and 2010 we have the following code:

     var encButton = ((CommandBarButton) commandBars.Value.FindControl(Type.Missing, 718, Type.Missing, false)))
                    return encButton != null && encButton.Visible;

    The encrypt button in Outlook is only available if a certificate is set. So it is enough to only check if the button is available to know if the user has a certificate set in the settings.

    Unfortunately this approach does not work anymore with Outlook 2013 because Microsoft stopped the support for commandbars. So searching the command bar returns null in 2013.

    Is there any other approach to either check the button in the fluent ribbon or to see if a certificate is set in the security settings?

    Thank you very much.


    Regards Mark

    Thursday, January 30, 2014 11:41 AM

Answers

  • Hi,

    thank you very much for your answers.

    In the end I found a workaround with Inspector.CommandBars.ExecuteMso("EncryptMessage");

    Even if CommandBars aren't available anymore in Office 2013 the above command works and activates the encrypt button. If there is no encrypt button it throws an exception E_FAIL.

    So if there is a certificate in the security settings the command does not throw an error. To deactivate the button again just call ExecuteMso twice.

    For now this workaround for outlook 2013 works, but maybe with the next office version this command will be outdated.

    Thanks again.


    Regards Mark



    Monday, February 3, 2014 2:39 PM

All replies

  • Hello Wompi,

    You are right. The button is not available in the Outlook UI any longer. Instead, you can find it going through the following steps:

    1. The Inspector window provides the Options tab which contains the More Options group.

    2. Clicking on the marked button you will see the Properties dialog:


    Thursday, January 30, 2014 12:10 PM
  • 3. Then you need to click Security Settings button in the dialog. You will see a new dialog window with the required options:

    Unfortunately the Outlook Object Model doesn't provide any trivial way for getting the value of security settings for a particular mail item. You can try to use OutlookSpy and look for any new custom properties set after you've changed the security settings.

    Thursday, January 30, 2014 12:10 PM
  • Hi Eugene,

    thank you very much for your answer.

    I will give it a try :)


    Regards Mark

    Friday, January 31, 2014 2:57 PM
  • I don't know if you can use Redemption (www.dimastr.com/redemption) in your code, but if you can you can get an RDOMail object in your code from an Outlook.MailItem, then you can try casting the RDOMail item as an RDOEncryptedMessage item. That provides properties for various certificate properties.

    If the cast returns a null object (or an exception) the item isn't being sent as an S/MIME message.


    Ken Slovak MVP - Outlook

    Friday, January 31, 2014 3:49 PM
    Moderator
  • Hi Ken,

    thank you very much for your answer.

    Unfortunately we can not use Redemption.

    Why can't VSTO be like Redemption :(


    Regards Mark

    Monday, February 3, 2014 9:06 AM
  • Mark,

    It is a disadvantage of Outlook object model, not VSTO. Outlook and Redemption are wrappers around Extended MAPI. So, you may use a low-level code provided by the Messaging API to bridge the gap.

    Monday, February 3, 2014 9:50 AM
  • Hi,

    thank you very much for your answers.

    In the end I found a workaround with Inspector.CommandBars.ExecuteMso("EncryptMessage");

    Even if CommandBars aren't available anymore in Office 2013 the above command works and activates the encrypt button. If there is no encrypt button it throws an exception E_FAIL.

    So if there is a certificate in the security settings the command does not throw an error. To deactivate the button again just call ExecuteMso twice.

    For now this workaround for outlook 2013 works, but maybe with the next office version this command will be outdated.

    Thanks again.


    Regards Mark



    Monday, February 3, 2014 2:39 PM
  • Good news! :)

    Thank you for sharing your solution for other forum readers. 

    Monday, February 3, 2014 3:35 PM