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) Fetch Inbox Email HeadersDownloads the headers of all emails in the Inbox and shows some information about each, such as From, Subject, and whether the email has been seen (already read) or not.
#include <CkImap.h> #include <CkEmailBundle.h> #include <CkEmail.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkImap imap; // Connect to an IMAP server. // Use TLS imap.put_Ssl(true); imap.put_Port(993); bool success = imap.Connect("imap.someMailServer.com"); if (success != true) { strOut.append(imap.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Login success = imap.Login("myLogin","myPassword"); if (success != true) { strOut.append(imap.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Select an IMAP mailbox success = imap.SelectMailbox("Inbox"); if (success != true) { strOut.append(imap.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Normally, when an email is downloaded, its "Seen" flag is automatically set. // We don't want our program to be interfering with the "Seen" flags. // To do this, set the PeekMode to true. imap.put_PeekMode(true); // After selecting the mailbox, the NumMessages property // will contain the number of emails in the mailbox. // When sequence numbers (not UIDs) are used to reference emails, // they range from 1 to N, where N is the number of messages in the mailbox. // This example will download the headers by sequence numbers. CkEmailBundle *bundle = imap.FetchSequenceHeaders(1,imap.get_NumMessages()); if (imap.get_LastMethodSuccess() != true) { strOut.append(imap.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } if (bundle->get_MessageCount() == 0) { strOut.append("No messages in Inbox."); strOut.append("\r\n"); delete bundle; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Loop over the email headers. int i; for (i = 0; i <= bundle->get_MessageCount() - 1; i++) { CkEmail *emailHeader = bundle->GetEmail(i); strOut.append(emailHeader->ck_from()); strOut.append("\r\n"); strOut.append(emailHeader->subject()); strOut.append("\r\n"); // Get the "Seen" flag. // When an email is fetched from the IMAP server, the email flags are stored // within the email in the "ckx-imap-flags" header. // The call to GetMailFlag is simply getting the information from the email header. // (it is not communicating with the IMAP server to get this information, because // the information was obtained when downloading the headers) int seenFlag = imap.GetMailFlag(*emailHeader,"Seen"); if (seenFlag == 1) { strOut.append("This email has been read (already seen)"); strOut.append("\r\n"); } else { strOut.append("This email has not yet been read (it is not yet seen)"); strOut.append("\r\n"); } // We can also look directly at the "ckx-imap-flags" header: strOut.append("ckx-imap-flags: "); strOut.append(emailHeader->getHeaderField("ckx-imap-flags")); strOut.append("\r\n"); strOut.append("--"); strOut.append("\r\n"); delete emailHeader; } delete bundle; // Disconnect from the IMAP server. success = imap.Disconnect(); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.