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

Read email headers and display the body as text

See more Email Object Examples

Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loEmail
LOCAL i
LOCAL lcReferenceId
LOCAL loReader

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.

loEmail = CreateObject('Chilkat.Email')
lnSuccess = loEmail.LoadEml("with-attachments.eml")
IF (lnSuccess <> 1) THEN
    ? loEmail.LastErrorText
    RELEASE loEmail
    CANCEL
ENDIF

? "From: " + loEmail.From
? "Subject: " + loEmail.Subject
? "Date: " + loEmail.EmailDateStr
i = 0
DO WHILE (i < loEmail.NumTo)
    ? "To: " + loEmail.GetToName(i) + "  " + loEmail.GetToAddr(i)
    i = i + 1
ENDDO
lcReferenceId = loEmail.GetHeaderField("X-Reference-ID")
IF (loEmail.LastMethodSuccess = 1) THEN
    ? "Reference: " + lcReferenceId
ENDIF

IF (loEmail.HasPlainTextBody() = 1) THEN
    ? loEmail.GetPlainTextBody()
ELSE
    IF (loEmail.HasHtmlBody() = 1) THEN
        loReader = CreateObject('Chilkat.HtmlToText')
        ? loReader.ToText(loEmail.GetHtmlBody())
    ELSE
        ? "No text or HTML body."
    ENDIF

ENDIF

RELEASE loEmail
RELEASE loReader