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

Xojo Plugin
Dim success As Boolean
success = False

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim email As New Chilkat.Email
success = email.LoadEml("with-attachments.eml")
If (success <> True) Then
    System.DebugLog(email.LastErrorText)
    Return
End If

System.DebugLog("From: " + email.From)
System.DebugLog("Subject: " + email.Subject)
System.DebugLog("Date: " + email.EmailDateStr)
Dim i As Int32
i = 0
While (i < email.NumTo)
    System.DebugLog("To: " + email.GetToName(i) + "  " + email.GetToAddr(i))
    i = i + 1
Wend
Dim referenceId As String
referenceId = email.GetHeaderField("X-Reference-ID")
If (email.LastMethodSuccess = True) Then
    System.DebugLog("Reference: " + referenceId)
End If

If (email.HasPlainTextBody() = True) Then
    System.DebugLog(email.GetPlainTextBody())
Else
    If (email.HasHtmlBody() = True) Then
        Dim reader As New Chilkat.HtmlToText
        System.DebugLog(reader.ToText(email.GetHtmlBody()))
    Else
        System.DebugLog("No text or HTML body.")
    End If

End If