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
  1. POP 
  2. IMAP 
  3. less secure apps
need to enable "less secure apps" on your Google Account
var (
from = "coco@gmail.com"
to = from
user = from
pwd = "gpwd"
host = `smtp.gmail.com`
port = 587
)


Comments

Popular posts from this blog

Go-VSCode -Autocomplete and Auto-import