GO mail toolkit to parse email content to an object.
Built on the standard library only (net/mail, mime, mime/multipart), requires Go 1.23 or later.
buffer, err := os.ReadFile("mail.eml")
if err != nil {
log.Fatal(err)
}
mail, err := mailtoolkit.Parse(buffer)
if err != nil {
// The mail is malformed or truncated, mail still holds what could be read.
log.Print(err)
}
fmt.Println(mail.Header.From, mail.Header.Subject)
for name, attachment := range mail.Attachments {
data, err := attachment.Decode() // removes base64 / quoted-printable
...
}ParseandParseHeaderreturn an error instead of panicking on malformed mails.ParseContentsand the exported regular expressions /MIMEContentTypesvariables are gone.Header.To,CcandBcchold every address (comma separated), not only the first one. The newToList,CcList, ... fields keep the display names.Subject,Content-Descriptionand attachment names are decoded (RFC 2047 / RFC 2231).- Part data no longer includes the line break preceding the next boundary.