I am trying to parse my emails in Go and I need help.
How to get access to Content-type field of mail?
cmd, _ = c.Fetch(set, "BODY[HEADER]", "BODY[1]")
for cmd.InProgress() {
for _, rsp = range cmd.Data {
header := imap.AsBytes(rsp.MessageInfo().Attrs["BODY[HEADER]"])
body := imap.AsString(rsp.MessageInfo().Attrs["BODY[1]"])
if msg, _ := mail.ReadMessage(bytes.NewReader(header)); msg != nil {
with this I can gain access to Body and Header, but when email contain included file then with BODY[1]
I have all meta-data, not only pure text. To avoid that I can use BODY[1.1]
, but I need condition by Content-Type:[multipart/alternative]
and I can't gain access ot that field.
Ok, so i figured it out by my self. But anyway, maybe someone else interested in that. You can have access to varios fields of mail by
msg.Header.Get("Content-type")
and instead of Content-type
you can put any header part name.
fmt.println(msg)
to know what name fields it have
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.