![]() |
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
(PHP ActiveX) 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.
<?php $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. $mailman = new COM("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'; $sbXml = new COM("Chilkat.StringBuilder"); $htSeenUidls = new COM("Chilkat.Hashtable"); $fac = new COM("Chilkat.FileAccess"); if ($fac->FileExists($seenUidlsPath) == 1) { $success = $sbXml->LoadFile($seenUidlsPath,'utf-8'); if ($success == 0) { print $sbXml->LastErrorText . "\n"; exit; } $htSeenUidls->AddFromXmlSb($sbXml); } // Get the complete list of UIDLs on the mail server. $stUidls = new COM("Chilkat.StringTable"); $success = $mailman->FetchUidls($stUidls); if ($success == 0) { print $mailman->LastErrorText . "\n"; exit; } // Build a list of unseen UIDLs $stUnseenUidls = new COM("Chilkat.StringTable"); $i = 0; $count = $stUidls->Count; while ($i < $count) { $uidl = $stUidls->stringAt($i); if ($htSeenUidls->Contains($uidl) != 1) { $stUnseenUidls->Append($uidl); } $i = $i + 1; } if ($stUnseenUidls->Count == 0) { print 'No unseen emails!' . "\n"; exit; } // Download the unseen emails, adding each UIDL to the "seen" hash table. $email = new COM("Chilkat.Email"); $count = $stUnseenUidls->Count; $i = 0; while ($i < $count) { // Download the full email. $uidl = $stUnseenUidls->stringAt($i); $success = $mailman->FetchByUidl($uidl,0,0,$email); if ($success == 0) { print $mailman->LastErrorText . "\n"; exit; } print $i . "\n"; print 'From: ' . $email->From . "\n"; print 'Subject: ' . $email->Subject . "\n"; // Add this UIDL to the "seen" hash table. $htSeenUidls->AddStr($uidl,''); $i = $i + 1; } $mailman->Pop3EndSession(); // Update the "seen" UIDLs file. $sbXml->Clear(); $htSeenUidls->ToXmlSb($sbXml); $success = $sbXml->WriteFile($seenUidlsPath,'utf-8',0); if ($success == 0) { print $sbXml->LastErrorText . "\n"; exit; } print 'Success.' . "\n"; ?> |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.