In previous section, I introduced how to send email with embedded images. In this section, I will introduce how to sign email with digital certificate in VB 6.0.
S/MIME (Secure/Multipurpose Internet Mail Extensions) is a standard for public key encryption and signing of MIME data.
Digital signature prevents email content is faked or changed in transport level. Encrypting email protects email content from exposure to inappropriate recipients. Both digital signature and email encrypting depend on digital certificate.
If you have an email digital signature certificate installed on your machine, you can find it in “Control Panel” -> “Internet Options” -> “Content” -> “Certificates” -> “Personal”.
Then you can use your email certificate to sign the email by the following code. If you don’t have a certificate for your email address, you MUST get a digital certificate for personal email protection from third-party certificate authorities such as www.verisign.com.
If you need a free certificate for your email address, you can go to http://www.comodo.com/home/email-security/free-email-certificate.php to apply for one year free email certificate.
Remarks: All of samples in this section are based on first section: Send email in a simple VB 6.0 project. To compile and run the following example codes successfully, please click here to learn how to create the test project and add reference of EASendMail to your project.
The following example codes demonstrate how to send email with digital signature in VB6.
To get the full sample projects, please refer to Samples section.
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 Command1_Click() Dim oSmtp As New EASendMailObjLib.Mail oSmtp.LicenseCode = "TryIt" ' Set your sender email address oSmtp.FromAddr = "email@example.com" ' Add recipient email address oSmtp.AddRecipientEx "firstname.lastname@example.org", 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 = "email@example.com" 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("firstname.lastname@example.org", _ 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
If you have any comments or questions about above example codes, please click here to add your comments.