VB.NET Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



VB.NET Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
PFX
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression
Misc

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Byte Array
VB.NET FTPS
System.IO

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

Email Distribution List with Mail Merge

VB.NET source code example showing how to send email using a distribution list with mail-merge.

        Dim success As Boolean = False

        ' Create a mailman object for sending email.
        Dim mailman As New Chilkat.MailMan()

        ' Any string argument automatically begins the 30-day trial.
        mailman.UnlockComponent("30-day trial")

        ' Set the SMTP server.
        mailman.SmtpHost = "smtp.earthlink.net"

        ' Create an array of email addresses.
        ' This is where you might load email addresses from a file,
        ' or load email addresses from a database such as Access, SQL Server, Oracle, MySQL, etc.
        Dim array As New Chilkat.StringArray()
        array.Unique = True ' Do not allow duplicates in the array.
        ' Chilkat will be able to parse the full email addresses...
        array.Append("Chilkat Support <support@chilkatsoft.com>")
        array.Append("""Chilkat Sales"" <sales@chilkatsoft.com>")
        array.Append("<matt@chilkatsoft.com>")
        array.Append("joe@chilkatsoft.com")

        Dim email As New Chilkat.Email()

        ' Make this email have both HTML and plain-text alternatives.
        ' Be sure to use CRLF line endings in plain-text email.
        email.AddPlainTextAlternativeBody("Hello CUSTOMER_NAME" + ControlChars.Cr + ControlChars.Lf + "This is a test")
        email.AddHtmlAlternativeBody("<html><body>Hello CUSTOMER_NAME<br>This is a test</body></html>")

        email.Subject = "CUSTOMER_NAME: This is a test."

        email.FromName = "Bob"
        email.FromAddress = "bob@chilkatsoft.com"

        Dim i As Integer
        Dim numEmails As Integer = array.Count

        Dim friendlyName As String
        For i = 0 To numEmails - 1
            email.ClearTo()

            ' We call AddMultipleTo even though we are only adding a single
            ' email address.  AddMultipleTo parses a comma separated list of
            ' email addresses, each of which may or may not include the
            ' friendly name.
            email.AddMultipleTo(array.GetString(i))

            ' Get the friendly name that was in the email address.
            friendlyName = email.GetToName(0)
            If friendlyName.Length = 0 Then
                friendlyName = friendlyName + "Customer"
            End If
            ' Set the replacement pattern.  When the email is sent, all occurances of 
            ' CUSTOMER_NAME are replaced with the replacement string.
            email.SetReplacePattern("CUSTOMER_NAME", friendlyName)

            ' The email can have any number of replacement patterns.  Simply 
            ' set a replace pattern for each.  
            ' email.SetReplacePattern("PATTERN2","replacement2");
            ' email.SetReplacePattern("PATTERN3","replacement3");
            Dim sendQueued As Boolean = True

            ' One option is to send the email in the background using the SMTPQ service:
            If sendQueued Then
                ' Sending the email using SMTPQ allows for emails to be sent by multiple
                ' threads simultaneously by the SMTPQ process.  The email sending will 
                ' also survive system reboots / crashes because it will resume when the
                ' service restarts on system startup.
                If Not mailman.SendQ(email) Then
                    ' We could send the email in-process:
                    MessageBox.Show(mailman.LastErrorText)
                    Exit For
                End If
            Else
                ' Or... the mail can be sent in-process.
                If Not mailman.SendEmail(email) Then
                    ' We could send the email in-process:
                    MessageBox.Show(mailman.LastErrorText)
                    Exit For
                End If
            End If
        Next i


Important: The download for this example does not contain the ChilkatDotNet.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/vbdotnet/step2.asp

 

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

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

Mail Component · XML Parser