![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Classic ASP) Reading Unread POP3 EmailThe POP3 protocol cannot determine which emails are "unread," and pure POP3 servers do not store this information. Servers like Exchange Server, offering both POP3 and IMAP interfaces, do contain read/unread data, but it's only accessible through IMAP. Email clients like Outlook and Thunderbird store read/unread statuses on the client side. The example demonstrates using UIDLs to track and manage "unread" emails. Note: This example requires Chilkat v11.0.0 or greater.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% success = 0 ' This example requires the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. ' The mailman object is used for receiving (POP3) ' and sending (SMTP) email. set mailman = Server.CreateObject("Chilkat.MailMan") ' Set the POP3 server's hostname mailman.MailHost = "pop.example.com" ' Set the POP3 login/password. mailman.PopUsername = "***" mailman.PopPassword = "***" ' Keep a records of already-seen UIDLs in hash table serialized to an XML file. seenUidlsPath = "c:/temp/seenUidls.xml" set sbXml = Server.CreateObject("Chilkat.StringBuilder") set htSeenUidls = Server.CreateObject("Chilkat.Hashtable") set fac = Server.CreateObject("Chilkat.FileAccess") If (fac.FileExists(seenUidlsPath) = 1) Then success = sbXml.LoadFile(seenUidlsPath,"utf-8") If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( sbXml.LastErrorText) & "</pre>" Response.End End If success = htSeenUidls.AddFromXmlSb(sbXml) End If ' Get the complete list of UIDLs on the mail server. set stUidls = Server.CreateObject("Chilkat.StringTable") success = mailman.FetchUidls(stUidls) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>" Response.End End If ' Build a list of unseen UIDLs set stUnseenUidls = Server.CreateObject("Chilkat.StringTable") i = 0 count = stUidls.Count Do While i < count uidl = stUidls.StringAt(i) If (htSeenUidls.Contains(uidl) <> 1) Then success = stUnseenUidls.Append(uidl) End If i = i + 1 Loop If (stUnseenUidls.Count = 0) Then Response.Write "<pre>" & Server.HTMLEncode( "No unseen emails!") & "</pre>" Response.End End If ' Download the unseen emails, adding each UIDL to the "seen" hash table. set email = Server.CreateObject("Chilkat.Email") count = stUnseenUidls.Count i = 0 Do While i < count ' Download the full email. uidl = stUnseenUidls.StringAt(i) success = mailman.FetchByUidl(uidl,0,0,email) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>" Response.End End If Response.Write "<pre>" & Server.HTMLEncode( i) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "From: " & email.From) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "Subject: " & email.Subject) & "</pre>" ' Add this UIDL to the "seen" hash table. success = htSeenUidls.AddStr(uidl,"") i = i + 1 Loop success = mailman.Pop3EndSession() ' Update the "seen" UIDLs file. sbXml.Clear success = htSeenUidls.ToXmlSb(sbXml) success = sbXml.WriteFile(seenUidlsPath,"utf-8",0) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( sbXml.LastErrorText) & "</pre>" Response.End End If Response.Write "<pre>" & Server.HTMLEncode( "Success.") & "</pre>" %> </body> </html> |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.