Link to home
Start Free TrialLog in
Avatar of darbid73
darbid73Flag for Germany

asked on

How to check if an Outlook mailItem is encrypted in a timely fashion?

I want to check if a mailItem with Outlook 2007 is encrypted or not.

I am pretty sure "THE" way of doing this would come from  Microsofts code here.

   
Dim oProp As Long
      oProp = CLng(Item.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))

Open in new window


The thing is that this code takes seconds to process and given that I am using outlook I must do it on the UI thread meaning everything is locked up.

I have tried accessing a property of the mailitem such as subject which will throw an error if the email is encrypted, but this also takes seconds to throw the error.

So is there some property, something else in the Outlook 2007 object model that will throw an exception if the mailItem is encrypted, but not lock up for seconds?

In case you are wondering what I want to do. I am trying to add a new Context button when the ItemContextMenuDisplay event is called and this button depends on whether the item is encrypted or not.
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Maybe you could adapt this macro. he was getting an error when he tried to copy.  Perhaps you could copy with VB.Net & trap the error for encrypted messages.  Maybe it's faster than your current method & won't lock up.

macro fails at
"Item.UnRead = False". I get a message that says "Run-time error
'-2147217660 (80040F04)':" / "Method 'UnRead' of object 'MailItem' failed - See more at: http://www.knowoutlook.com/view/206201-error-with-item-unread-false-for-encrypted-messages.html#sthash.6zuKmgyS.dpuf

Public WithEvents myOlItems2 As Outlook.Items

Public Sub Application_Startup()
Set myOlItems2 = Outlook.Session.Folders("Personal
Folders").Folders("Inbox").Folders("Sent (2007)").Items
End Sub

Public Sub myOlItems2_ItemAdd(ByVal Item As Object)

Dim myOlAppSub As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim mySentFolder As Outlook.MAPIFolder

Set myOlAppSub = CreateObject("Outlook.Application")
Set myNameSpace = myOlAppSub.GetNamespace("MAPI")
Set mySentFolder = myNameSpace.Folders("Personal
Folders").Folders("Inbox").Folders("Sent (2007)")

Item.UnRead = False
End Sub - See more at: http://www.knowoutlook.com/view/206201-error-with-item-unread-false-for-encrypted-messages.html#sthash.6zuKmgyS.dpuf

Open in new window

Avatar of darbid73

ASKER

Thanks for the reply. The Unread property of a mailItem can be read on any email irrespective of encryption status.  So there is no error to catch.  

The guy in the post is in a world of confusion. Not sure why he needs all those objects in the ItemAdd method.  My guess why he is getting an error is because "item" can be any Outlook item but the property Unread might not be a property on all Outlook items.  I noticed no body answered the real forum question (not knowoutlook which is some scraper of forums) but my guess is that he needs to check the item type/class is a mailitem first.
ASKER CERTIFIED SOLUTION
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The solution is to check the MessageClass. In my case an encrypted email is "IPM.Note.SMIME"

But this is only a solution for Office 2007 / 2010.  This is not shown in 2003 and I have not tested it on 2013.

Thanks for making me check this again. I had done this during office 2003 but had forgotten to try it again now for 2007 / 2010.