Sample code for 30+ languages & platforms
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 C Downloads

C
#include <C_CkMailMan.h>
#include <C_CkEmail.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMailMan mailman;
    HCkEmail partialEmail;
    HCkEmail 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 = CkMailMan_Create();

    //  Configure the POP3 server connection.
    CkMailMan_putMailHost(mailman,"pop.example.com");
    CkMailMan_putMailPort(mailman,995);
    CkMailMan_putPopSsl(mailman,TRUE);
    CkMailMan_putPopUsername(mailman,"user@example.com");
    CkMailMan_putPopPassword(mailman,"myPassword");

    //  First fetch message 1 as headers only (a fast preview).  headerOnly=TRUE.
    partialEmail = CkEmail_Create();

    success = CkMailMan_FetchOne(mailman,TRUE,0,1,partialEmail);
    if (success == FALSE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        CkMailMan_Dispose(mailman);
        CkEmail_Dispose(partialEmail);
        return;
    }

    printf("Preview subject: %s\n",CkEmail_subject(partialEmail));

    //  Now download the complete message (body and attachments).
    fullEmail = CkEmail_Create();
    success = CkMailMan_FetchFull(mailman,partialEmail,fullEmail);
    if (success == FALSE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        CkMailMan_Dispose(mailman);
        CkEmail_Dispose(partialEmail);
        CkEmail_Dispose(fullEmail);
        return;
    }

    printf("Full email NumAttachments: %d\n",CkEmail_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.


    CkMailMan_Dispose(mailman);
    CkEmail_Dispose(partialEmail);
    CkEmail_Dispose(fullEmail);

    }