mhale / smtpd

An SMTP server package written in Go, in the style of the built-in HTTP server.
The Unlicense
404 stars 92 forks source link

how to get the body of the email? #34

Closed hiqsociety closed 1 year ago

hiqsociety commented 1 year ago

great work! i've managed to get everything set up but dunno how to get the body of the msg. I know how to get the subject but how do i get the body?

    msg, _ := mail.ReadMessage(bytes.NewReader(data))
    subject := msg.Header.Get("Subject")
    log.Printf("Received mail from %s for %s with subject %s", from, to[0], subject)
    return nil
mhale commented 1 year ago

You probably want something like:

    body, err := io.ReadAll(msg.Body)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s", body)

There is a full example in the mail package docs.

hiqsociety commented 1 year ago

just figured out. thx!