SignerCert Property


This property specifies the Digital Signature of current email.

Data Type: Object

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.

vb6 sign email with certificate

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 sign email content with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.

[VB6, VBA - Sign Email with Certificate]
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 btnSendMail_Click() 

    Dim oSmtp As New EASendMailObjLib.Mail 
    oSmtp.LicenseCode = "TryIt" 

    ' 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 email from VB 6.0 with digital signature" 

    ' Set email body
    oSmtp.BodyText = "this is a test email sent from VB 6.0 with digital signature" 

    ' Your SMTP server address
    oSmtp.ServerAddr = "smtp.emailarchitect.net" 

    ' User and password for ESMTP authentication, if your server doesn't require
    ' User authentication, please remove the following codes.
    oSmtp.UserName = "test@emailarchitect.net" 
    oSmtp.Password = "testpassword" 

    ' If your smtp server requires SSL connection, please add this line
    ' oSmtp.SSL_init

    ' 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 

    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 Email with Certificate]
#include "stdafx.h" 

#include "easendmailobj.tlh" 
using namespace EASendMailObjLib; 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    ::CoInitialize( NULL ); 

    IMailPtr oSmtp = NULL; 
    oSmtp.CreateInstance( __uuidof(EASendMailObjLib::Mail)); 
    oSmtp->LicenseCode = _T("TryIt"); 

    // 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("email from Visual C++ with digital signature(S/MIME)"); 

    // Set email body
    oSmtp->BodyText = _T("this is a test email sent from Visual C++ with digital signature"); 

    // Your SMTP server address
    oSmtp->ServerAddr = _T("smtp.emailarchitect.net"); 

    // User and password for ESMTP authentication, if your server doesn't
    // require User authentication, please remove the following codes.
    oSmtp->UserName = _T("test@emailarchitect.net"); 
    oSmtp->Password = _T("testpassword"); 

    // If your SMTP server requires SSL connection, please add this line
    //oSmtp->SSL_init();

    // 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; 
    } 

    _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()); 
    } 

    if( oSmtp != NULL ) 
        oSmtp.Release(); 

    return 0; 
} 

[Delphi - Sign Email with Certificate]
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 
  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; 
Begin 
  oSmtp := TMail.Create(Application); 
  oSmtp.LicenseCode := 'TryIt'; 

  // 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 email from Delphi with digital signature'; 

  // Set body text
  oSmtp.BodyText := 'this is a test 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; 

  // Your SMTP server address
  oSmtp.ServerAddr := 'smtp.emailarchitect.net'; 

  // User and password for ESMTP authentication, if your server doesn't require
  // user authentication, please remove the following codes
  oSmtp.UserName := 'test@emailarchitect.net'; 
  oSmtp.Password := 'testpassword'; 

  // If your SMTP server requires SSL connection, please add this line
  // oSmtp.SSL_init();

  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. 

Online Examples

Sign Email - VB 6.0
Encrypt Email - VB 6.0
Sign Email - Visual C++
Encrypt Email - Visual C++
Sign Email - Delphi
Encrypt Email - Delphi

See Also

SignatureHashAlgorithm Property
RecipientsCerts Property
Digital Signature and E-mail Encryption (S/MIME)