如何检查邮件是否具有有效的数字签名 - VBA

时间:2016-10-21 12:20:46

标签: vba outlook-vba mapi

我有一个功能,可以找到包含主题的特定邮件,我还想添加一些方法来查明邮件是否有有效的数字签名。

Set objOutlook = CreateObject("Outlook.Application") 
Set myNameSpace = objOutlook.GetNameSpace("MAPI")   
Set ClientFolder = myNameSpace.GetDefaultFolder(6) 'Inbox = 6 
Set myItems = ClientFolder.Items 
Set myItem = myItems.GetFirst 
Set colSyc = myNameSpace.SyncObjects
Set syc = colSyc.AppFolders
ClientFolder.InAppFolderSyncObject = True 
syc.Start 'Sync inbox at most updated state

For intMailCount = 0 to ClientFolder.Items.Count - 1 ' Check subject line for a match       
    If Instr(myItem.Subject, Subject) = 1 AND myItem.Unread = True then             
        VerifyEmailSubject = "True" 

    'validation under here does not work properly and allways returns true and need to find something here for validation
    If myItem.MessageClass <> "IPM.Note.SMIME" Or myItem.MessageClass <> "IPM.Note.Secure" Or myItem.MessageClass <> "IPM.Note.Secure.Sign" then
        msgbox "signed"
    End If
        myItem.Unread = false   'Set mail status to read to avoid further test assertion errors.    
    Exit For        
End If 
    Set myItem = myItems.GetNext 
Next 

1 个答案:

答案 0 :(得分:0)

解决了

If myItem.MessageClass = "IPM.Note.SMIME.MultipartSigned" Then 
    VerifyEmailSignature = "True"   
End If