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
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+35.9k Golang : Integer is between a range
+3.7k Golang : Switch Redis database redis.NewClient
+15.9k Golang : Get current time from the Internet time server(ntp) example
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+15.7k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+15.4k Golang : Find location by IP address and display with Google Map
+17.2k Golang : Find file size(disk usage) with filepath.Walk
+10.3k Golang : Convert file unix timestamp to UTC time example
+40.5k Golang : Convert to io.ReadSeeker type
+7.5k Golang : Shuffle strings array
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date