Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loWrapper
LOCAL loNested
LOCAL i

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.

loWrapper = CreateObject('Chilkat.Email')
lnSuccess = loWrapper.LoadEml("forward-as-attachment.eml")
IF (lnSuccess <> 1) THEN
    ? loWrapper.LastErrorText
    RELEASE loWrapper
    CANCEL
ENDIF

? "Cover note: " + loWrapper.Subject
IF (loWrapper.NumAttachedMessages = 0) THEN
    ? "No attached messages."
    RELEASE loWrapper
    CANCEL
ENDIF

loNested = CreateObject('Chilkat.Email')
i = 0
DO WHILE (i < loWrapper.NumAttachedMessages)
    lnSuccess = loWrapper.GetAttachedEmail(i,loNested)
    IF (lnSuccess <> 1) THEN
        ? loWrapper.LastErrorText
        RELEASE loWrapper
        RELEASE loNested
        CANCEL
    ENDIF

    ? "Original author: " + loNested.From
    ? "Original subject: " + loNested.Subject
    ? "Files on the original: " + STR(loNested.NumAttachments)
    i = i + 1
ENDDO

RELEASE loWrapper
RELEASE loNested