Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
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
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.