Unicode C
Unicode C
Download the Full Version of a Partial Email
See more POP3 Examples
Demonstrates the Chilkat MailMan.FetchFull method, which downloads the complete version of a header-only or partial Email and stores it in a second Email. The full result includes the complete body and any attachments, and the partial email must retain its UIDL. This example previews message 1 (headers only) and then downloads it in full.
Background: A common pattern is to download headers first — cheap and fast — show the user a message list, and only pull the full content when a message is actually opened.
FetchFull completes that "download on demand" flow: given a partial email (which carries its UIDL), it fetches the rest from the server. This keeps bandwidth and latency low when browsing a large mailbox.Chilkat Unicode C Downloads
#include <C_CkMailManW.h>
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkMailManW mailman;
HCkEmailW partialEmail;
HCkEmailW fullEmail;
success = FALSE;
// Demonstrates the MailMan.FetchFull method, which downloads the complete version of a
// header-only or partial Email and stores it in a second Email. The full result includes
// the complete body and any attachments. The partial email must retain its UIDL.
mailman = CkMailManW_Create();
// Configure the POP3 server connection.
CkMailManW_putMailHost(mailman,L"pop.example.com");
CkMailManW_putMailPort(mailman,995);
CkMailManW_putPopSsl(mailman,TRUE);
CkMailManW_putPopUsername(mailman,L"user@example.com");
CkMailManW_putPopPassword(mailman,L"myPassword");
// First fetch message 1 as headers only (a fast preview). headerOnly=TRUE.
partialEmail = CkEmailW_Create();
success = CkMailManW_FetchOne(mailman,TRUE,0,1,partialEmail);
if (success == FALSE) {
wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
CkMailManW_Dispose(mailman);
CkEmailW_Dispose(partialEmail);
return;
}
wprintf(L"Preview subject: %s\n",CkEmailW_subject(partialEmail));
// Now download the complete message (body and attachments).
fullEmail = CkEmailW_Create();
success = CkMailManW_FetchFull(mailman,partialEmail,fullEmail);
if (success == FALSE) {
wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
CkMailManW_Dispose(mailman);
CkEmailW_Dispose(partialEmail);
CkEmailW_Dispose(fullEmail);
return;
}
wprintf(L"Full email NumAttachments: %d\n",CkEmailW_getNumAttachments(fullEmail));
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
CkMailManW_Dispose(mailman);
CkEmailW_Dispose(partialEmail);
CkEmailW_Dispose(fullEmail);
}