VB.NET Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB.NET Examples

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

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

Byte Array
VB.NET FTPS
System.IO

 

 

 

 

 

 

Read IMAP Email and Forward to Another Remote Email Account

Download Chilkat .NET for 4.0 Framework

Download Chilkat .NET for 64-bit 4.0 Framework (x64)

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 64-bit 2.0 / 3.5 Framework (x64)

Download Chilkat .NET for 1.0 / 1.1 Framework

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





 

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

Mail Component · XML Parser