Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Process Large POP3 MailboxDemonstrates how to read email from a mailbox that may contain a large number of emails.
#include <CkMailMan.h> #include <CkStringArray.h> #include <CkEmailBundle.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkMailMan mailman; mailman.put_MailHost("pop.example.com"); mailman.put_PopUsername("myLogin"); mailman.put_PopPassword("myPassword"); mailman.put_MailPort(995); mailman.put_PopSsl(true); // Get the list of UIDLs for all emails in the mailbox. CkStringArray *sa = mailman.GetUidls(); if (mailman.get_LastMethodSuccess() == false) { strOut.append(mailman.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } int i; int numEmails = sa->get_Count(); if (numEmails == 0) { strOut.append("Mailbox is empty"); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } int chunkSize = 6; // Download the emails in chunks of 6 emails each. int chunkBeginIdx = 0; int chunkEndIdx = chunkSize - 1; if (chunkEndIdx >= numEmails) { chunkEndIdx = numEmails - 1; } CkStringArray saChunk; while ((chunkBeginIdx < numEmails)) { strOut.appendInt(chunkBeginIdx); strOut.append(" to "); strOut.appendInt(chunkEndIdx); strOut.append("\r\n"); // Build a chunk of UIDLs. saChunk.Clear(); for (i = chunkBeginIdx; i <= chunkEndIdx; i++) { saChunk.Append(sa->getString(i)); } // Log the UIDLs in this chunk... const char *chunkStr = saChunk.saveToText(); strOut.append(chunkStr); strOut.append("\r\n"); // Download this chunk of email from the POP3 server. CkEmailBundle *bundle = mailman.FetchMultiple(saChunk); if (mailman.get_LastMethodSuccess() == false) { strOut.append(mailman.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append("Downloaded "); strOut.appendInt(bundle->get_MessageCount()); strOut.append(" emails."); strOut.append("\r\n"); strOut.append("----"); strOut.append("\r\n"); // Process the bundle... // (your application's processing code goes here...) delete bundle; // Get the next chunk... chunkBeginIdx = chunkBeginIdx + chunkSize; chunkEndIdx = chunkEndIdx + chunkSize; if (chunkEndIdx >= numEmails) { chunkEndIdx = numEmails - 1; } } delete sa; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.