尚方宝剑之说
我现在想出了如何获取正文。cmd, _ = c.UIDFetch(set, "RFC822.HEADER", "RFC822.TEXT")// Process responses while the command is runningfmt.Println("\nMost recent messages:")for cmd.InProgress() { // Wait for the next response (no timeout) c.Recv(-1) // Process command data for _, rsp = range cmd.Data { header := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.HEADER"]) uid := imap.AsNumber((rsp.MessageInfo().Attrs["UID"])) body := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.TEXT"]) if msg, _ := mail.ReadMessage(bytes.NewReader(header)); msg != nil { fmt.Println("|--", msg.Header.Get("Subject")) fmt.Println("UID: ", uid) fmt.Println(string(body)) } } cmd.Data = nil c.Data = nil}