package gmailApi
import (
"encoding/base64"
"fmt"
"net/mail"
"strings"
)
func SendEmailVerification() {
if err != nil {
fmt.Println(err) // BUG(Vincent): TEST
}
// New message for our gmail service to send
var message gmail.Message
// Compose the message
// @ symbol modified for publishing on golang-nuts
messageStr := []byte(
"Subject: My first Gmail API message\r\n\r\n" +
"Message body goes here!")
// Place messageStr into message.Raw in base64 encoded format
message.Raw = base64.URLEncoding.EncodeToString(messageStr)
if rslt, err := srv.Users.GetProfile("me").Do(); err != nil {
fmt.Println(err) // BUG(Vincent): TEST
} else {
fmt.Println("111", rslt)
}
msg := ComposeMessage()
_, err = srv.Users.Messages.Send("me", msg).Do()
if err != nil {
fmt.Println(err) // BUG(Vincent): TEST
} else {
fmt.Println("OKOKOK")
}
}
func ComposeMessage() *gmail.Message {
from := mail.Address{
"Vincent",
"vincent[at]gamifly.gg"} // @ symbol modified for publishing on golang-nuts
to := mail.Address{
"Vincent",
"jouglardv[at]gmail.com"} // @ symbol modified for publishing on golang-nuts
header := make(map[string]string)
header["From"] = from.String()
header["To"] = to.String()
header["Subject"] = encodeRFC2047("Hello, Gmail!")
header["MIME-Version"] = "1.0"
header["Content-Type"] = "text/plain; charset=\"utf-8\""
header["Content-Transfer-Encoding"] = "base64"
var msg string
for k, v := range header {
msg += fmt.Sprintf("%s: %s\r\n", k, v)
}
msg += "\r\n" + "Message"
return &gmail.Message{
Raw: base64.RawURLEncoding.EncodeToString([]byte(msg)),
}
}
func encodeRFC2047(s string) string {
// use mail's rfc2047 to encode any string
addr := mail.Address{s, ""}
return strings.Trim(addr.String(), " <>")
}