Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Sending Signed Email in VB with a Specific Digital Certificate
This example source code creates and sends a digitally signed email using a specific X.509 digital certificate loaded from a registry certificate store or a DER-encoded X.509 .cer file.
' VB example program to send a digitally signed email using
' certificate loaded from the registry-based Current User Certificate Store.
Private Sub Command1_Click()
' Find the certificate that we will use to sign the email.
' ChilkatCreateCS1 is a ChilkatCreateCS object that has been
' dropped onto the Visual Basic form.
Dim certStore As ChilkatCertStore
Set certStore = ChilkatCreateCS1.OpenCurrentUserStore()
Dim cert As ChilkatCert
Set cert = certStore.FindCertBySubjectE("matt@chilkatsoft.com")
' We could've loaded the certificate from a DER encoded X.509 .cer file.
'Set cert = New ChilkatCert
'cert.LoadFromFile "matt.cer"
' Create the mailman object for sending mail.
Dim mailman As ChilkatMailMan2
Set mailman = New ChilkatMailMan2
' Any string value will begin the 30-day trial.
mailman.UnlockComponent "UnlockCode"
' Set our SMTP server to be used for sending signed mail.
mailman.SmtpHost = "smtp.earthlink.net"
' Only set username/password if your SMTP server requires a logon.
'mailman.SmtpUsername = "your_username"
'mailman.SmtpPassword = "your_password"
' Only set the login domain if your SMTP server uses integrated Windows authorization
' AND it is part of a domain.
'mailman.SmtpLoginDomain = "your_domain"
' Create the mail object.
Dim email As ChilkatEmail2
Set email = New ChilkatEmail2
' Assign the cert to the email so that it is used when signing the email.
email.SetSigningCert cert
email.AddTo "Email Expert", "support@chilkatsoft.com"
email.Subject = "This is the subject"
email.Body = "This is the body"
email.From = "matt@chilkatsoft.com"
' Indicate that the email should be sent digitally signed.
' When sending a signed email, the private key is used, so the private key
' associated with the chosen certificate must be installed on the system.
email.SendSigned = 1
' Send mail. Returns 1 for success, 0 for failure
Dim success As Long
success = mailman.SendEmail(email)
' Display the details of the certificate used in signing.
Text1.Text = "Sent signed email with certificate:" & vbCrLf
Text1.Text = Text1.Text & "certificate serial number: " & cert.SerialNumber & vbCrLf
Text1.Text = Text1.Text & "certificate subject common name: " & cert.SubjectCN & vbCrLf
Text1.Text = Text1.Text & "certificate subject email: " & cert.SubjectE & vbCrLf
' Save the log regardless of success/failure
If (success = 1) Then
MsgBox "Mail Sent!"
Else
MsgBox mailman.LastErrorText
End If
End Sub
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.