Golang net/mail.Header type, Date(), Get() and AddressList() functions example
package net/mail
Golang net/mail.Header type, Date(), Get() and AddressList() functions usage example
package main
import (
"fmt"
"net/mail"
)
var header = mail.Header{
"From": []string{"Adam <adam@earth.net>"},
"To": []string{"Eve <eve@earth.net>"},
"Subject": []string{"I don't want to eat the apple.."},
"Date": []string{"Fri, 21 Nov 0000 09:55:06 -0600"},
"Message-Id": []string{"<9999@tree.earth.net>"},
}
func main() {
key := "From"
address, err := header.AddressList(key)
if err != nil {
panic(err)
}
fmt.Println(address[0].String())
// --------------
key = "To"
addresses, err := header.AddressList(key)
if err != nil {
panic(err)
}
fmt.Println(addresses[0].String())
// --------------
dateTime, err := header.Date()
if err != nil {
panic(err)
}
fmt.Println(dateTime.String())
// --------------
getSubject := header.Get("Subject")
fmt.Println(getSubject)
}
Output :
"Adam" adam@earth.net
"Eve" eve@earth.net
0000-11-21 09:55:06 -0600 -0600
I don't want to eat the apple..
References :
http://golang.org/pkg/net/mail/#Header
http://golang.org/pkg/net/mail/#Header.AddressList
Advertisement
Something interesting
Tutorials
+7k Golang : Reverse text lines or flip line order example
+20.4k Golang : Use TLS version 1.2 and enforce server security configuration over client
+18.6k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+6.5k Gogland : Single File versus Go Application Run Configurations
+10.4k Golang : Get remaining text such as id or filename after last segment in URL path
+7.2k Swift : Convert (cast) Character to Integer?
+20.1k SSL : How to check if current certificate is sha1 or sha2
+10.6k Golang : Detect user location with HTML5 geo-location
+16k Golang : Qt image viewer example
+11.9k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+21k Golang : Read a file into an array or slice example
+9.6k PHP : Convert(cast) bigInt to string