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

Byte Array
VB.NET FTPS
System.IO

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

Read IMAP Email and Forward to Another Remote Email Account

This example answers the following customer question: How do I read all the email from an IMAP mailbox, forward it to another email account (on a remote mail server) and then delete the email?

        ' Read email from one mailbox and forward to another email account
        ' elsewhere on the Web.
        Dim imap As New Chilkat.Imap
        imap.UnlockComponent("anything for 30-day trial")

        ' If SSL is required, set the Port and Ssl properties:
        'imap.Port = 993
        'imap.Ssl = True

        ' Connect to the IMAP server.
        imap.Connect("mail.chilkatsoft.com")

        ' Login
        If Not (imap.Login("myLogin", "myPassword")) Then
            MessageBox.Show(imap.LastErrorText)
            Exit Sub
        End If

        ' Select a mailbox
        If (Not imap.SelectMailbox("Inbox")) Then
            MessageBox.Show(imap.LastErrorText)
            Exit Sub
        End If

        ' Get ALL messages.
        Dim msgSet As Chilkat.MessageSet
        msgSet = imap.Search("ALL", True)

        ' Fetch all email into a StringArray object.
        ' Each message within the StringArray is the full MIME source of an email.
        Dim sa As Chilkat.StringArray
        sa = imap.FetchBundleAsMime(msgSet)

        ' Setup our SMTP server properties.
        Dim mailman As New Chilkat.MailMan
        mailman.SmtpHost = "smtp.comcast.net"

        ' Authentication may or may not be required, depending on your situation...
        'mailman.SmtpUsername = "myLogin"
        'mailman.SmtpPassword = "myPassword"

        Dim i As Long
        Dim strFrom As String
        Dim strRecipients As String
        Dim success As Boolean

        strFrom = "matt@chilkatsoft.com"
        strRecipients = "somebody@somewhere.com"

        Dim totalSuccess As Boolean
        totalSuccess = True

        For i = 0 To sa.Count - 1
            ' Forward the email to the other address...
            success = mailman.SendMime(strFrom, strRecipients, sa.GetString(i))
            If (Not success) Then
                totalSuccess = False
                Exit For
            End If
        Next

        ' Mark each message as deleted and expunge
        If (totalSuccess) Then
            imap.SetFlags(msgSet, "Deleted", 1)
            imap.ExpungeAndClose()
        End If





 

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

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

Mail Component · XML Parser