Chilkat ActiveX Components

  Chilkat .NET Components

  Chilkat C++ Libraries

Email SMTP .NET Component .NET SMTP / POP3 Email Component

ASP.NET SMTP Send Example Source Code Snippets

The full source code for these examples are provided in the ChilkatDotNet.msi download at http://www.chilkatsoft.com/downloads.asp

ASP.NET SMTP: Send an Encrypted Email using a Certificate

    '=======================================================================================
    '
    ' Example 6
    '
    ' Send a digitally encrypted email
    '
    ' For this example, our email will be very simple -- just a plain text email with
    ' no attachments.  However, when an encrypted email is sent, everything 
    ' is encrypted -- all attachments, HTML images, etc.
    '
    '=======================================================================================

    ' Create a Chilkat.MailMan object for sending,
    ' and set the necessary properties and unlock the component.
    Dim mailman as New Chilkat.MailMan()
    mailman.UnlockComponent(Request.form("unlockCode"))

    ' Tell the MailMan the SMTP server to be used for sending email.
    mailman.SmtpHost = Request.form("smtpServer")

    ' Optionally provide the SMTP server with a login and password.
    ' The MailMan will automatically choose the most secure SMTP authorization
    ' method available.
    if Request.form("smtpLogin") <> "" then
    	mailman.SmtpUsername = Request.form("smtpLogin")
    	mailman.SmtpPassword = Request.form("smtpPassword")
    end if

    ' Create an Email object.  The mailman will send the email.
    Dim email As New Chilkat.Email()
   
    ' Give our email a subject, recipient, and return address.
    email.From = Request.form("fromAddr")
    email.AddTo("",Request.form("recipient"))
    email.Subject = "Chilkat ASP.NET " + Request.form("exampleSelected")

    Response.Write("Sending encrypted email!")

    ' Our body is plain text, so give it a simple body:
    email.Body = "This is a plain-text, encrypted email" + vbcrlf + "I hope that was easy!"
    
    email.SendEncrypted = true

    Dim cert as New Chilkat.Cert
    cert.SetFromEncoded(Request.form("encryptCert"))

    email.SetEncryptCert(cert)

    ' Make sure we use something strong enough.
    ' The Microsoft Base Cryptographic Provider is the default,and it defaults to 40-bit RC2
    ' encryption, which is weak. The Enhanced Provider, which is most likely already on your
    ' computer, provides stonger default protection (128-bit).  You can also optionally select
    ' 3DES encryption by uncommenting the line below.
    Dim csp as New Chilkat.Csp
    csp.SetProviderMicrosoftEnhanced
    'csp.SetEncryptAlgorithm("3DES")
    email.SetCSP(csp)


    ' Connect to the SMTP server and send mail.
    if (mailman.SendEmail(email)) then

    	Response.write("Mail sent!")

    else

    	Response.write("Errors in sending email!")
    	Response.write(mailman.LastErrorHtml)

    end if

 

Copyright 2000-2005 Chilkat Software, Inc. All rights reserved.
Components for Microsoft Windows XP, 2000, NT, 95/98/ME