[英]Parse email fields with Golang
I am trying to parse my emails in Go and I need help. 我正在尝试在Go中解析我的电子邮件,我需要帮助。
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. 这样,我就可以访问“正文”和“标题”,但是当电子邮件包含包含的文件时,使用
BODY[1]
我将拥有所有元数据,而不仅仅是纯文本。 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. 为了避免这种情况,我可以使用
BODY[1.1]
,但是我需要使用Content-Type:[multipart/alternative]
并且无法访问该字段。
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. 而不是
Content-type
您可以放置任何标题部分的名称。
fmt.println(msg)
to know what name fields it have 知道它有什么名字字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.