This property specifies the certificates of recipients to encrypt current email.
EASendMail uses built-in Certificate and CertificateCollection object to sign and encrypt email.
You must assign each certificate for each recipient.
Usage Example:
[Visual Baisc]
Const CRYPT_MACHINE_KEYSET = 32
Const CRYPT_USER_KEYSET = 4096
Const CERT_SYSTEM_STORE_CURRENT_USER = 65536
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072
Private Sub SendEmail()
Dim oSmtp As EASendMailObjLib.Mail
Set oSmtp = New EASendMailObjLib.Mail
'The license code for EASendMail ActiveX Object,
'for evaluation usage, please use "TryIt" as the license code.
oSmtp.LicenseCode = "TryIt"
Dim Sender As String
Sender = "test@adminsystem.net"
oSmtp.ServerAddr = "mail.adminsystem.net"
oSmtp.FromAddr = Sender
'clear certificate
oSmtp.SignerCert.Unload
'find certificate in current user certificate store
If Not oSmtp.SignerCert.FindSubject("test@adminsystem.net", CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
MsgBox oSmtp.SignerCert.GetLastError()
End If
'you can also load signer cerificate from a cer file
'If Not oSmtp.SignerCert.LoadPFXFromFile("c:\cert\my.pfx", "password of this certificate", _
CRYPT_USER_KEYSET ) Then
'MsgBox oSmtp.SignerCert.GetLastError()
'End If
If Not oSmtp.SignerCert.HasPrivateKey Then
MsgBox "Signer certificate has not private key, this certificate can not be used to sign email!"
End If
Dim arRecipients(3) As String
arRecipients(0) = "support@adminsystem.net"
arRecipients(1) = "support1@adminsystem.net"
arRecipients(2) = "support2@adminsystem.net"
Dim i, nCount As Long
nCount = 3
'clear certificate
oSmtp.RecipientsCerts.Clear
For i = 0 To nCount - 1
Dim oEncryptCert As New EASendMailObjLib.Certificate
'find certificate by recipient email address
If Not oEncryptCert.FindSubject(arRecipients(i), CERT_SYSTEM_STORE_CURRENT_USER, "AddressBook") Then
If Not oEncryptCert.FindSubject(arRecipients(i), CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
MsgBox oEncryptCert.GetLastError()
Exit Sub 'no certificate foud, exit subroutine
End If
End If
'you can also load encrypting cerificate from a pfx file
'If Not oEncryptCert.LoadCertFromFile("c:\cert\my.cer" ) Then
'MsgBox oEncryptCert.GetLastError()
'Exit Sub 'no certificate foud, exit subroutine
'End If
'add recipient certificate
oSmtp.RecipientsCerts.Add oEncryptCert
oSmtp.AddRecipient arRecipients(i), arRecipients(i), 0
Next
oSmtp.Subject = "Test"
oSmtp.BodyText = "Hello, this is a test...."
If oSmtp.SendMail() = 0 Then
MsgBox "Message delivered!"
Else
MsgBox oSmtp.GetLastErrDescription()
End If
End Sub
See Also