AddRecipientCert Method


Adds the certificate having the specified parameters to the list of certificates which are used for subsequent encryption of the message.

To encrypt a message, the developer must specify at least one public certificate of the recipient. The method performs search over the the specified certificate storage accordingly the specified search criteria and picks the first matching certificate. If the message has multiple recipients, this method must be called for each recipient.

When the message gets delivered to the recipients, they will be able to decrypt it using their private certificates assuming you encrypted it using their public certificates.


[Visual Basic]

blnResult = ObjectName.AddRecipientCert(Store, StoreType, IssuedTo, IssuedBy, FriendlyName, Email)

 
Parameters:  
Store As String

The name of the digital 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

If empty, Mailbee uses "AddressBook" value.

 
StoreType As Long

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

  • REGISTRY_STORE = 0 - standard system storage which belongs to the current user
  • FILE_STORE = 1 - file storage
  • PFX_STORE = 2 - PFX file
 
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 PFX file password, in case of a PFX_STORE.  
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 loads the message from file, encrypts it and saves it to disk. It's assumed the message has only a single recipient.
Dim objSMIME, objMsg ' Using Visual Basic to create the objects Set objMsg = CreateObject("MailBee.Message") Set objSMIME = CreateObject("MailBee.SMIME") ' Using ASP to create the objects 'Set objMsg = Server.CreateObject("MailBee.Message") 'Set objSMIME = Server.CreateObject("MailBee.SMIME") ' Specify MailBee license key objSMIME.LicenseKey = "put your license key here" ' Load the message from file objMsg.ImportFromFile "mail_src.eml" ' Specify the message for the further processing Set objSMIME.Message = objMsg ' Add the recipient's certificate for the message encryption from the system storage If objSMIME.AddRecipientCert("AddressBook", 0, "", "", "", objMsg.PureToAddr) Then ' Encrypt the message objSMIME.Encrypt End If ' Check if any errors occurred If (objSMIME.SMIMEError <> SMIME_OK) Or (objSMIME.SMIMESpecificError <> SMIME_OK) Then ' Display the code of the last occurred error ' In ASP use Response.Write instead of MsgBox MsgBox "SMIMEError = " & objSMIME.SMIMEError & " SMIMESpecificError = " & _ objSMIME.SMIMESpecificError End If ' Get the encrypted message Set objMsg = objSMIME.Message ' Save the message to disk objMsg.SaveMessage "mail_dst.eml"

See Also:

SelectSenderCert Method, AddSignerToStore Method


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