Turn on “2-Step Verification” so that an “App password” can be generated
go get gopkg.in/gomail.v2
Send your Email like the example below:
package main
import (
"gopkg.in/gomail.v2"
)
func main() {
m := gomail.NewMessage()
m.SetHeader("From", "[email protected]")
m.SetAddressHeader("To", "to_adress@xxx", "to_name")
m.SetAddressHeader("Cc", "cc_adress@xxx", "cc_name")
m.SetHeader("Subject", "Hello! TEST!")
m.SetBody("text/html", "Hello! <b>TEST</b>!")
d := gomail.NewPlainDialer("smtp.gmail.com", 587, "[email protected]", "the App password")
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}