Golang net/mail.Message type and ReadMessage() function example
package net/mail
Golang net/mail.Message type and ReadMessage() function usage example
package main
import (
"bytes"
"fmt"
"net/mail"
)
var emailData = `From: Adam <adam@earth.com>
To: Eve <eve@earth.com>
Subject: Do not eat the apple from that tree!
Date: Fri, 21 Nov 0000 09:55:06 -0600
Message-ID: <1234@garden.earth>
Don't listen to that snake. Don't eat the apple!
`
func main() {
msg, err := mail.ReadMessage(bytes.NewBuffer([]byte(emailData)))
if err != nil {
panic(err)
}
fmt.Println(msg.Header)
// convert io.Reader type to string
buf := new(bytes.Buffer)
buf.ReadFrom(msg.Body)
s := buf.String()
fmt.Println(s)
}
Output :
map[Date:[Fri, 21 Nov 0000 09:55:06 -0600] Message-Id:[1234@garden.earth] From:[Adam adam@earth.com] To:[Eve eve@earth.com] Subject:[Do not
eat the apple from that tree!]]
Don't listen to that snake. Don't eat the apple!
References :
Advertisement
Something interesting
Tutorials
+10.5k Golang : Generate random integer or float number
+11.6k CodeIgniter : Import Linkedin data
+5.8k Get website traffic ranking with Similar Web or Alexa
+11.6k Use systeminfo to find out installed Windows Hotfix(s) or updates
+5.5k Golang : Return multiple values from function
+7.2k Golang : Gargish-English language translator
+9.6k Golang : Qt Yes No and Quit message box example
+7.7k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+9.8k PHP : Get coordinates latitude/longitude from string
+8k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+10.5k Golang : Meaning of omitempty in struct's field tag
+29.6k Golang : How to create new XML file ?