Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual Basic 6.0 Examples
Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual Basic 6.0) Reading Unread POP3 Email

The 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Dim success As Long
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.
Dim mailman As New ChilkatMailMan

' 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.
Dim seenUidlsPath As String
seenUidlsPath = "c:/temp/seenUidls.xml"

Dim sbXml As New ChilkatStringBuilder
Dim htSeenUidls As New ChilkatHashtable
Dim fac As New CkFileAccess
If (fac.FileExists(seenUidlsPath) = 1) Then
    success = sbXml.LoadFile(seenUidlsPath,"utf-8")
    If (success = 0) Then
        Debug.Print sbXml.LastErrorText
        Exit Sub
    End If

    success = htSeenUidls.AddFromXmlSb(sbXml)
End If

' Get the complete list of UIDLs on the mail server.
Dim stUidls As New ChilkatStringTable
success = mailman.FetchUidls(stUidls)
If (success = 0) Then
    Debug.Print mailman.LastErrorText
    Exit Sub
End If

' Build a list of unseen UIDLs
Dim stUnseenUidls As New ChilkatStringTable

Dim uidl As String
Dim i As Long
i = 0
Dim count As Long
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
    Debug.Print "No unseen emails!"
    Exit Sub
End If

' Download the unseen emails, adding each UIDL to the "seen" hash table.
Dim email As New ChilkatEmail

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
        Debug.Print mailman.LastErrorText
        Exit Sub
    End If

    Debug.Print i
    Debug.Print "From: " & email.From
    Debug.Print "Subject: " & email.Subject

    ' 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
    Debug.Print sbXml.LastErrorText
    Exit Sub
End If

Debug.Print "Success."

 

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