Golang — Sentmail
Jan 13, 2021
- Setting SMTP Gmail
ตาม URL >> https://thanaroj09.medium.com/sent-email-gmail-setting-ee577489c74f
2. Code golang ประมาณนี้
package main
import (
“log”
“net/smtp”
)func main() {
send(“hello there”)
}func send(body string) {
from := “…@gmail.com”
pass := “…”
to := “thanaroj@gmail.com”
msg := “From: “ + from + “\n” +
“To: “ + to + “\n” +
“Subject: Hello there\n\n” + bodyerr := smtp.SendMail(“smtp.gmail.com:587”, smtp.PlainAuth(“”, from, pass, “smtp.gmail.com”), from, []string{to}, []byte(msg))
if err != nil {
log.Printf(“smtp error: %s”, err)
return
}
log.Print(“sent, visit http://thanaroj.com")}