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

Go
    success := false

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

    email := chilkat.NewEmail()
    success = email.LoadEml("with-attachments.eml")
    if success != true {
        fmt.Println(email.LastErrorText())
        email.DisposeEmail()
        return
    }

    fmt.Println("From: ", email.From())
    fmt.Println("Subject: ", email.Subject())
    fmt.Println("Date: ", email.EmailDateStr())
    i := 0
    for (i < email.NumTo()) {
        fmt.Println("To: ", *email.GetToName(i), "  ", *email.GetToAddr(i))
        i = i + 1
    }

    referenceId := email.GetHeaderField("X-Reference-ID")
    if email.LastMethodSuccess() == true {
        fmt.Println("Reference: ", *referenceId)
    }

    if email.HasPlainTextBody() == true {
        fmt.Println(*email.GetPlainTextBody())
    } else {
        if email.HasHtmlBody() == true {
            reader := chilkat.NewHtmlToText()
            fmt.Println(*reader.ToText(*email.GetHtmlBody()))
        } else {
            fmt.Println("No text or HTML body.")
        }

    }


    email.DisposeEmail()
    reader.DisposeHtmlToText()