Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

Sending Signed Email in VB with 160-bit SHA-1 using the CSP object

Download Chilkat Email ActiveX

This example source code sends a digitally signed email and uses the ChilkatCSP object to select a specific hash algorithm (SHA-1). It automatically finds and selects the digital certificate based on the From email address. This is the quickest and easiest way to send a digitally signed email. This program should work if you already have Outlook configured and are able to send signed mail from Outlook.

' VB example program to send a digitally signed email.
Private Sub Command1_Click()

    ' Create the mailman object for sending mail.
    Dim mailman As ChilkatMailMan2
    
    Set mailman = New ChilkatMailMan2
    
    'Any string will begin the 30-day fully-functional 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
    
    email.AddTo "Email Expert", "support@chilkatsoft.com"
    email.Subject = "This is the subject"
    email.Body = "This is the body"
    email.From = "matt@chilkatsoft.com"
    
    ' To send encrypted and/or signed emails, just set either or both of these flags.
    ' Chilkat Mail will automatically find the certificates based on the From / To
    ' email addresses.  For signing, the certificate matching the From email address
    ' is used.  For encryption, the certificate matching the To email address is used.
    ' 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.
    ' In general, if you have Outlook setup correctly and you are able to send
    ' signed emails using Outlook, this should work.  Sending a signed email is
    ' nothing more than setting the SendSigned property to 1.
    email.SendSigned = 1
    'email.SendEncrypted = 1
    
    ' You have full control over the encryption and hash algorithms by using
    ' a ChilkatCSP (Cryptographic Service Provider) object.
    ' Create the CSP object, set the CSP properties, and then assign the CSP to the email.
    Dim csp As ChilkatCSP
    Set csp = New ChilkatCSP
    csp.SetProviderMicrosoftEnhanced

    ' Display the algorithms available through this CSP
    ' The output of this is:
    ' CSP: Microsoft Enhanced Cryptographic Provider v1.0
    ' Encryption Algorithms
    ' RC2
    ' RC4
    ' DES
    ' 3DES TWO KEY
    ' 3DES
    ' Hash Algorithms
    ' SHA -1
    ' MD2
    ' MD4
    ' MD5
    ' SSL3 SHAMD5
    ' Mac
    ' HMAC
    ' SHA-1: 160 bits

    Text1.Text = "CSP: " & csp.ProviderName & vbCrLf
    Text1.Text = Text1.Text & "Encryption Algorithms" & vbCrLf
    For i = 0 To csp.NumEncryptAlgorithms - 1
        Text1.Text = Text1.Text & csp.GetEncryptionAlgorithm(i) & vbCrLf
    Next
    Text1.Text = Text1.Text & "Hash Algorithms" & vbCrLf
    For i = 0 To csp.NumHashAlgorithms - 1
        Text1.Text = Text1.Text & csp.GetHashAlgorithm(i) & vbCrLf
    Next
    
    ' Choose the SHA-1 hash algorithm for signing.
    csp.SetHashAlgorithm "SHA-1"
    
    ' How many bits?
    Text1.Text = Text1.Text & csp.HashAlgorithm & ": " & csp.HashNumBits & " bits" & vbCrLf
    Text1.Refresh
        
    ' Use this CSP with 160-bit SHA-1 for signing
    email.SetCSP csp
    
    ' Send mail.  Returns 1 for success, 0 for failure
    Dim success As Long
    success = mailman.SendEmail(email)
    
    ' Save the log regardless of success/failure
    If (success = 1) Then
        MsgBox "Signed email sent!"
    Else
        MsgBox mailman.LastErrorText
    End If
    
            
End Sub


 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.