Sample code for 30+ languages & platforms
Visual FoxPro

Download MIME Source of Emails in IMAP Mailbox

Demonstrates how to download the MIME source for emails on an IMAP server.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL lnNumMessages
LOCAL loSbMime
LOCAL lnSeqNum

lnSuccess = 0

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loImap = CreateObject('Chilkat.Imap')

* Connect to an IMAP server.
* Use TLS
loImap.Ssl = 1
loImap.Port = 993
lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

* Login
lnSuccess = loImap.Login("myLogin","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

* Select an IMAP mailbox
lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

* The NumMessages property contains the number of messages in the selected mailbox.
lnNumMessages = loImap.NumMessages
IF (lnNumMessages = 0) THEN
    ? "No messages exist in the Inbox."
    RELEASE loImap
    CANCEL
ENDIF

loSbMime = CreateObject('Chilkat.StringBuilder')

FOR lnSeqNum = 1 TO lnNumMessages
    loSbMime.Clear()
    lnSuccess = loImap.FetchSingleAsMimeSb(lnSeqNum,0,loSbMime)
    IF (lnSuccess = 0) THEN
        ? loImap.LastErrorText
        RELEASE loImap
        RELEASE loSbMime
        CANCEL
    ENDIF

    * The MIME source of the downloaded email is contained in sbMime.
NEXT

* Disconnect from the IMAP server.
lnSuccess = loImap.Disconnect()

RELEASE loImap
RELEASE loSbMime