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
+12.3k Golang : Verify token from Google Authenticator App
+4.4k PHP : Hide PHP version information from curl
+29k Golang : Calculate percentage change of two values
+19.6k Golang : Create and resolve(read) symbolic links
+13.3k Golang : How to filter a map's elements for faster lookup
+16.6k Golang : Get all upper case or lower case characters from string example
+2.2k Golang : Switch Redis database redis.NewClient
+12.7k Android Studio : Use image as AlertDialog title with custom layout example
+11.6k Golang : Convert int(year) to time.Time type
+18.8k nginx: [emerg] unknown directive "passenger_enabled"
+5.5k Golang : Calculate diameter, circumference, area, sphere surface and volume