EnumerateCerts Method


Enumerates the certificates in a store based on the specified search criteria.

You can use this method to filter a certificate store and find the certificates matching certain criteria (or simply list all the certificates in the store). You can then pick a particular certificate as a sender's signing certificate (SMIME.SelectSenderCert method) or encryption certificate (SMIME.AddRecipientCert method), passing the certificate's unique CertInfo.Sha1Hash value.

You can also use this method to check if the certificate with a certain SHA1 hash actually exists in the store.

If all search criteria are empty, MailBee will return all the certificates in the store.


[Visual Basic]

blnResult = ObjectName.SelectSenderCert(Path, StoreType, IssuedTo, IssuedBy, FriendlyName, Email, PfxPassword, Sha1Hash)

 
Parameters:  
Path As String

The name of the certificate's storage. The following names are supported for the system storage (REGISTRY_STORE):

  • MY - the personal user's certificates storage
  • AddressBook - other people certificates storage
  • CA - Intermediate Certification Authorities
  • Root - Trusted Root Certification Authorities

When using a file storage (FILE_STORE or FILE_PFX_STORE) this parameter should contain the name of this file storage.

 

If empty , MailBee uses "MY" value.

 
StoreType As Long

The type of the certificate's storage. MailBee supports the following types of certificate's storages:

  • REGISTRY_STORE = 0 - the standard system storage which belongs to the current user (not applicable for web applications which are usually run under the special system user, not the interactive user)
  • FILE_STORE = 1 - file storage
  • FILE_PFX_STORE = 2 - password-protected PFX file storage
 
IssuedTo As String The name of a person or organization to whom the certificate was issued. If empty, will not perform certificate search by this field.  
IssuedBy As String The name of a person or organization by whom the certificate was issued. If empty, will not perform certificate search by this field.  
FriendlyName As String The friendly name of a person to whom the certificate was issued. If empty, will not perform certificate search by this field.  
Email As String The e-mail address associated with the certificate. If empty, will not perform certificate search by this field.  
PfxPassword As String The password which should be used to access the certificates storage if it's a PFX file. If the password is not used, leave it an empty string.  
Sha1Hash As String 40-char hex string denoting the certificate's unique SHA1 hash. If this parameter is set, other search criteria are ignored. If empty, MailBee won't perform search by SHA1 hash.  
Return value As Boolean True if successful, False if error has occurred or no certificate matching the specified search criteria has been found.  

Usage example:

' This example enumerates the certificates of the sender, picks the first one which is not expired yet, and signs the message with it.
' This is useful in case if the user has both valid and expired certificates for the same email address in their MY store.

Dim SMIME, Msg, Hash, Result
Set Msg = CreateObject("MailBee.Message")
Msg.FromAddr = "bob@domain.com"
Msg.ToAddr = "alice@domain.com"
Msg.Subject = "Test"
Set SMIME = CreateObject("MailBee.SMIME")
SMIME.LicenseKey = "put your license key here"
Set SMIME.Message = Msg

Set Certs = SMIME.EnumerateCerts("MY", 0, "", "", "", Msg.PureFromAddr, "")
Hash = ""
For Each Cert in Certs
  ' Check that the certificate has not expired yet
  If Cert.ExpirationDate > Date Then
    Hash = Cert.Sha1Hash
    Exit For
  End If
Next

If Hash = "" Then
  MsgBox "Can't find the certificate suitable for signing"
Else
  Result = SMIME.SelectSenderCert("MY", 0, "", "", "", "", "", Hash)
  If Result Then
    Result = SMIME.Sign
    If Result Then
      SMIME.Message.SaveMessage "C:\Temp\test.eml"
    End If
  End If
End If

If SMIME.SMIMEError <> 0 Then
  MsgBox "SMIMEError=" & SMIME.SMIMEError & ", SMIMESpecificError=" & SMIME.SMIMESpecificError
End If


See Also:

SelectSenderCert Method, Sign Method


Copyright © 2002-2026, AfterLogic Corporation. All rights reserved.