This property specifies the hash algorithm for email digital signature. SHA256 is recommended.
Data Type: Long
Set the property to one of the following values:
| Value | Meaning |
| 0 | RSA\SHA1(Default) |
| 1 | RSA\SHA256 |
| 2 | RSA\SHA384 |
| 3 | RSA\SHA512 |
| 4 | RSA\MD5 |
Remarks
Digital signature is always signed by sender certificate. The certificate used to sign email content MUST have the public/private key pair. First of all, the user MUST get a digital certificate for personal email protection from third-party certificate authorities such as www.verisign.com. After the certificate is installed on the machine, it can be viewed by "Control Pannel" -> "Internet Options" -> "Content" -> "Certificates" -> "Personal". When you view the certificate, please note there is a line "You have a private key that corresponds to this certificate" in the certificate view, that means you are able to use this certificate to sign email content. If this line doesn't appear, that means you are unable to sign the email content by this certificate. To sign email content with EASendMail, the certificate with private key is required to be imported to Mail.SignerCert properly.
EASendMail uses built-in Certificate and CertificateCollection object to sign and encrypt email.
Example
[Visual Basic, Visual C++, Delphi] The following example demonstrates how to load certificate to encrypt email with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.
[VB6, VBA - Sign and Encrypt Email]
Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4
Const CRYPT_MACHINE_KEYSET = 32
Const CRYPT_USER_KEYSET = 4096
Const CERT_SYSTEM_STORE_CURRENT_USER = 65536
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072
Const CERT_STORE_PROV_LDAP_STORE = 16
Private Sub btnSignEncryptEmail_Click()
Dim oSmtp As New EASendMailObjLib.Mail
oSmtp.LicenseCode = "TryIt"
' Your SMTP server address
oSmtp.ServerAddr = "smtp.emailarchitect.net"
' User and password for ESMTP authentication
oSmtp.UserName = "test@emailarchitect.net"
oSmtp.Password = "testpassword"
' If server supports SSL/TLS connection, SSL/TLS is used automatically.
oSmtp.ConnectType = ConnectTryTLS
' Set your sender email address
oSmtp.FromAddr = "test@emailarchitect.net"
' Add recipient email address
oSmtp.AddRecipientEx "support@emailarchitect.net", 0
' Set email subject
oSmtp.Subject = "test encrypted email from VB 6.0 project"
' Set email body
oSmtp.BodyText = "this is a test encrypted email sent from VB 6.0 project"
' Add digital signature
If Not oSmtp.SignerCert.FindSubject("test@emailarchitect.net", _
CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
MsgBox oSmtp.SignerCert.GetLastError()
Exit Sub
End If
If Not oSmtp.SignerCert.HasPrivateKey Then
MsgBox "Signer certificate has not private key, " & _
" this certificate can not be used to sign email!"
Exit Sub
End If
' Find the encrypting certificate for every recipients
Dim oEncryptCert As New EASendMailObjLib.Certificate
If Not oEncryptCert.FindSubject("support@emailarchitect.net", _
CERT_SYSTEM_STORE_CURRENT_USER, "AddressBook") Then
If Not oEncryptCert.FindSubject("support@emailarchitect.net", _
CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
MsgBox oEncryptCert.GetLastError()
Exit Sub
End If
End If
' Add encrypting certificate
oSmtp.RecipientsCerts.Add oEncryptCert
MsgBox "start to send email ..."
If oSmtp.SendMail() = 0 Then
MsgBox "email was sent successfully!"
Else
MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription()
End If
End Sub
[VC++- Sign and Encrypt Email]
#include "stdafx.h"
#include <tchar.h>
#include <Windows.h>
#include "EASendMailObj.tlh"
using namespace EASendMailObjLib;
const int ConnectNormal = 0;
const int ConnectSSLAuto = 1;
const int ConnectSTARTTLS = 2;
const int ConnectDirectSSL = 3;
const int ConnectTryTLS = 4;
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
IMailPtr oSmtp = NULL;
oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail));
oSmtp->LicenseCode = _T("TryIt");
// Your SMTP server address
oSmtp->ServerAddr = _T("smtp.emailarchitect.net");
// User and password for ESMTP authentication
oSmtp->UserName = _T("test@emailarchitect.net");
oSmtp->Password = _T("testpassword");
// If server supports SSL/TLS connection, SSL/TLS is used automatically.
oSmtp->ConnectType = ConnectTryTLS;
// Set your sender email address
oSmtp->FromAddr = _T("test@emailarchitect.net");
// Add recipient email address
oSmtp->AddRecipientEx(_T("support@emailarchitect.net"), 0);
// Set email subject
oSmtp->Subject = _T("Encrypted email from Visual C++ (S/MIME)");
// Set email body
oSmtp->BodyText = _T("this is a test encrypted email sent from Visual C++");
//add signer digital signature
if(oSmtp->SignerCert->FindSubject(_T("test@emailarchitect.net"),
CERT_SYSTEM_STORE_CURRENT_USER , _T("my")) == VARIANT_FALSE)
{
_tprintf(_T("Error with signer certificate; %s\r\n"),
(const TCHAR*)oSmtp->SignerCert->GetLastError());
return 0;
}
if(oSmtp->SignerCert->HasPrivateKey == VARIANT_FALSE)
{
_tprintf(_T("certificate does not have a private key, it can not sign email.\r\n"));
return 0;
}
// Find the encrypting certificate for every recipients
ICertificatePtr oCert = NULL;
oCert.CreateInstance(__uuidof(EASendMailObjLib::Certificate));
if(oCert->FindSubject(_T("support@emailarchitect.net"),
CERT_SYSTEM_STORE_CURRENT_USER, _T("AddressBook")) == VARIANT_FALSE)
{
if(oCert->FindSubject(_T("support@emailarchitect.net"),
CERT_SYSTEM_STORE_CURRENT_USER, _T("my")) == VARIANT_FALSE)
{
_tprintf(_T("Encrypting certificate not found; %s\r\n"),
(const TCHAR*)oCert->GetLastError());
oCert.Release();
return 0;
}
}
// Add encrypting certificate
oSmtp->RecipientsCerts->Add(oCert);
oCert.Release();
_tprintf(_T("Start to send email ...\r\n"));
if(oSmtp->SendMail() == 0)
{
_tprintf(_T("email was sent successfully!\r\n"));
}
else
{
_tprintf(_T("failed to send email with the following error: %s\r\n"),
(const TCHAR*)oSmtp->GetLastErrDescription());
}
return 0;
}
[Delphi - Sign and Encrypt Email]
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, EASendMailObjLib_TLB; // add EASendMail Unit
Type
TForm1 = Class(TForm)
Button1: TButton;
Procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
End;
Const
ConnectNormal = 0;
ConnectSSLAuto = 1;
ConnectSTARTTLS = 2;
ConnectDirectSSL = 3;
ConnectTryTLS = 4;
CRYPT_MACHINE_KEYSET = 32;
CRYPT_USER_KEYSET = 4096;
CERT_SYSTEM_STORE_CURRENT_USER = 65536;
CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072;
CERT_STORE_PROV_LDAP_STORE = 16;
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Procedure TForm1.Button1Click(Sender: TObject);
Var
oSmtp : TMail;
oEncryptCert : TCertificate;
Begin
oSmtp := TMail.Create(Application);
oSmtp.LicenseCode := 'TryIt';
// Your SMTP server address
oSmtp.ServerAddr := 'smtp.emailarchitect.net';
// User and password for ESMTP authentication
oSmtp.UserName := 'test@emailarchitect.net';
oSmtp.Password := 'testpassword';
// If server supports SSL/TLS connection, SSL/TLS is used automatically.
oSmtp.ConnectType := ConnectTryTLS;
// Set your sender email address
oSmtp.FromAddr := 'test@emailarchitect.net';
// Add recipient email address
oSmtp.AddRecipientEx('support@emailarchitect.net', 0);
// Set email subject
oSmtp.Subject := 'test encrypted email from Delphi with digital signature';
// Set body text
oSmtp.BodyText := 'this is a test encrypted email sent from Delphi with digital signature';
// Add digital signature
If Not oSmtp.SignerCert.FindSubject('test@emailarchitect.net',
CERT_SYSTEM_STORE_CURRENT_USER, 'my') Then
Begin
ShowMessage(oSmtp.SignerCert.GetLastError());
exit;
End;
If Not oSmtp.SignerCert.HasCertificate Then
Begin
ShowMessage('Signer certificate has no private key, ' +
'this certificate can not be used to sign email');
End;
// Find the encrypting certificate for every recipients
oEncryptCert := TCertificate.Create(Application);
If Not oEncryptCert.FindSubject('support@emailarchitect.net',
CERT_SYSTEM_STORE_CURRENT_USER, 'AddressBook') Then
If Not oEncryptCert.FindSubject('support@emailarchitect.net',
CERT_SYSTEM_STORE_CURRENT_USER, 'my') Then
Begin
ShowMessage(oEncryptCert.GetLastError());
exit;
End;
// Add encrypting certificate
oSmtp.RecipientsCerts.Add(oEncryptCert.DefaultInterface);
ShowMessage('start to send email ...');
If oSmtp.SendMail() = 0 Then
ShowMessage('email was sent successfully!')
Else
ShowMessage('failed to send email with the following error: '
+ oSmtp.GetLastErrDescription());
End;
End.
[VB6, VBA - Find Certificate in Active Directory by LDAP]
Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4
Const CRYPT_MACHINE_KEYSET = 32
Const CRYPT_USER_KEYSET = 4096
Const CERT_SYSTEM_STORE_CURRENT_USER = 65536
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072
Const CERT_STORE_PROV_LDAP_STORE = 16
Private Sub btnEncryptEmail_Click()
Dim oSmtp As New EASendMailObjLib.Mail
oSmtp.LicenseCode = "TryIt"
' Your SMTP server address
oSmtp.ServerAddr = "smtp.emailarchitect.net"
' User and password for ESMTP authentication
oSmtp.UserName = "test@emailarchitect.net"
oSmtp.Password = "testpassword"
' If server supports SSL/TLS connection, SSL/TLS is used automatically.
oSmtp.ConnectType = ConnectTryTLS
' Set your sender email address
oSmtp.FromAddr = "test@emailarchitect.net"
' Add recipient email address
oSmtp.AddRecipientEx "Support <support@emailarchitect.net>", 0
' Set email subject
oSmtp.Subject = "test encrypted email from VB 6.0 project"
' Set email body
oSmtp.BodyText = "this is a test encrypted email sent from VB 6.0 project"
' Add digital signature
If Not oSmtp.SignerCert.FindSubject("test@emailarchitect.net", _
CERT_SYSTEM_STORE_CURRENT_USER, "my") Then
MsgBox oSmtp.SignerCert.GetLastError()
Exit Sub
End If
If Not oSmtp.SignerCert.HasPrivateKey Then
MsgBox "Signer certificate has not private key, " & _
" this certificate can not be used to sign email!"
Exit Sub
End If
' Please change the ldap path as your environment.
Dim oEncryptCert As New EASendMailObjLib.Certificate
If Not oEncryptCert.FindSubject("support@emailarchitect.net", _
CERT_STORE_PROV_LDAP_STORE, "ldap:///CN=Support,CN=USERS,DC=my,DC=server?userCertificate") Then
MsgBox oEncryptCert.GetLastError()
Exit Sub
End If
' Add encrypting certificate
oSmtp.RecipientsCerts.Add oEncryptCert
MsgBox "start to send email ..."
If oSmtp.SendMail() = 0 Then
MsgBox "email was sent successfully!"
Else
MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription()
End If
End Sub
See Also
SignerCert Property
Digital Signature and E-mail Encryption
RecipientsCerts Property