Go - mail
package main
import (
"crypto/tls"
"fmt"
gomail "gopkg.in/gomail.v2"
)
func main() {
from := "eve@hello.com.tw"
to := "eve@gmail.com"
user := "eve"
pwd := "pwd"
host := `smtp.hello.com.tw`
port := 25
m := gomail.NewMessage()
m.SetHeader("From", from)
m.SetHeader("To",to)
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello <b>Eve</b>!")
d := gomail.NewDialer(host, port, user, pwd)
d.TLSConfig = &tls.Config{InsecureSkipVerify:true}
if err := d.DialAndSend(m); err != nil {
panic(err)
}
fmt.Println("mail send successfully!")
}
gmail need to enable
- POP
- IMAP
- less secure apps
Comments
Post a Comment