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.
If you need to pick the certificate not just by its email address or friendly name but by some more advanced logic (for instance, to exclude expired versions of the
certificate), you can use EnumerateCerts method to find the desired certificate first, then pass its SHA1 hash (CertInfo.Sha1Hash value) to AddRecipientCert method.
|
[Visual Basic] blnResult = ObjectName.AddRecipientCert(Store, StoreType, IssuedTo, IssuedBy, FriendlyName, Email, PfxPassword, Sha1Hash) |
||
| Parameters: | ||
| Store As String |
The name of the digital certificate's storage. The following names are supported for the system storage (REGISTRY_STORE):
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:
|
|
| 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. | |
| 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 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 <> 0) Or (objSMIME.SMIMESpecificError <> 0) 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-2026, AfterLogic Corporation. All rights reserved.