Programming Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3

 

 

 

 

 

 

 

 

IMAP Download All Email One at a Time

Demonstrates how to download every email in an IMAP mailbox one at a time as a MIME string or as an email object. (The MIME contains the full contents of the email including all attachments.)

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
#include <C_CkImap.h>
#include <C_CkEmail.h>

void ChilkatSample(void)
    {
    HCkImap imap;
    BOOL success;
    BOOL bUid;
    const char * mimeStr;
    long i;
    long n;
    HCkEmail email;

    imap = CkImap_Create();

    //  Anything unlocks the component and begins a fully-functional 30-day trial.
    success = CkImap_UnlockComponent(imap,"Anything for 30-day trial");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  Connect to an IMAP server.
    success = CkImap_Connect(imap,"mail.chilkatsoft.com");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  Login
    success = CkImap_Login(imap,"myLogin","myPassword");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  Select an IMAP mailbox
    success = CkImap_SelectMailbox(imap,"Inbox");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  Once the mailbox is selected, the NumMessages property
    //  will contain the number of messages in the mailbox.
    //  You may loop from 1 to NumMessages to
    //  fetch each message by sequence number.

    bUid = FALSE;

    n = CkImap_getNumMessages(imap);
    for (i = 1; i <= n; i++) {

        //  Download the email by sequence number.
        mimeStr = CkImap_fetchSingleAsMime(imap,i,bUid);

        //  ... your application may process each MIME string...
    }

    //  An alternative is to download each email in the form of an
    //  email object, like this:

    for (i = 1; i <= n; i++) {

        //  Download the email by sequence number.
        email = CkImap_FetchSingle(imap,i,bUid);

        //  ... your application may process the email object...

        CkEmail_Dispose(email);
    }

    //  Disconnect from the IMAP server.
    CkImap_Disconnect(imap);



    CkImap_Dispose(imap);

    }

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.