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 Unread POP3 Email
Visual Basic example code to read email from a POP3 server that has not yet been read. ' VB6 program to fetch new email that has not yet been downloaded.
On Error Resume Next
' There is nothing in the POP3 protocol that allows for "new" or "unread" emails
' to be downloaded. The read/unread status of an email is not available via the
' POP3 protocol. This means programs must save the read/unread status locally.
Dim mailman As New ChilkatMailMan2
mailman.UnlockComponent "Anything for 30-day trial"
' Set our mail host and login
mailman.MailHost = "mail.chilkatsoft.com"
mailman.PopUsername = "myLogin"
mailman.PopPassword = "myPassword"
' Assume that the already-seen UIDLs are saved to a .txt file
' containing one UIDL per line.
' Load this file into our already-seen CkStringArray
Dim saAlreadySeen As New CkStringArray
saAlreadySeen.LoadFromFile "alreadySeenUidls.txt"
Dim sa As CkStringArray
Set sa = mailman.GetUidls()
MsgBox mailman.LastErrorText
' In a real application, you should check to make sure a Null
' object reference is not returned (indicating that GetUidls failed)
' Build a set of UIDLs that haven't yet been downloaded.
Dim saUidlsToDownload As New CkStringArray
' For each UIDL on the POP3 server, if it's not present in saAlreadySeen,
' add it to saUidlsToDownload
numUidls = sa.Count
For i = 0 To numUidls - 1
Uidl = sa.GetString(i)
If (saAlreadySeen.Contains(Uidl) = 0) Then
' Not already seen.
saUidlsToDownload.Append Uidl
End If
Next
' Download the emails in saUidlsToDownload
Dim bundle As ChilkatEmailBundle2
If (saUidlsToDownload.Count > 0) Then
Set bundle = mailman.FetchMultiple(saUidlsToDownload)
' Your application should check to make sure bundle is not a NULL
' object reference (indicating that FetchMultiple failed)
' Update alreadySeenUidls.txt with the exact set of UIDLs on the
' POP3 server so that the next time this is run, only the
' new emails will be downloaded.
sa.SaveToFile ("alreadySeenUidls.txt")
' We can now process the downloaded emails in any way we like...
numMessages = bundle.MessageCount()
Dim email As ChilkatEmail2
For i = 0 To numMessages - 1
Set email = bundle.GetEmail(i)
List1.AddItem email.Subject
List1.AddItem email.From
List1.AddItem "----"
Next
End If
MsgBox "Done!"
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.