SelectSenderCert Method


Specifies the certificate to be used to sign a new message.

To sign a new message, the developer must first specify a certificate with this method. The method performs search over the the specified certificate storage accordingly the specified search criteria and picks the first matching certificate. Once the certificate is selected, you can actually call the Sign method.

For this method to work, you must select the certificate which has the same associated email address as the one you specified with FromAddr Property of the mail message to be signed.


[Visual Basic]

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

 
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.  
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 5 messages from files, signs them and saves them to disk using the same instance of SMIME class.

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"

' Iterate through the messages
For i = 1 To 5
	' Load the message from file
	objMsg.ImportFromFile "mail_src" & i & ".eml"

	' Specify the message for the further processing
	Set objSMIME.Message = objMsg

	' Select the sender's certificate from the system storage of the current user
	' It's assumed all messages do have valid From and objMsg.PureFromAddr is not empty for them
	If objSMIME.SelectSenderCert ("MY", 0, "", "", "", objMsg.PureFromAddr, "") Then
		' Sign the message
		objSMIME.Sign
	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 signed message from SMIME object
Set objMsg = objSMIME.Message ' Save the signed message to disk objMsg.SaveMessage "mail_dst" & i & ".eml" ' Reset the SMIME object objSMIME.Reset Next

See Also:

AddRecipientCert Method, Sign Method


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