Skip to content

Instantly share code, notes, and snippets.

@KentaGoto
Last active December 24, 2019 08:00
Show Gist options
  • Select an option

  • Save KentaGoto/d19661386db75203211bc7604eff3096 to your computer and use it in GitHub Desktop.

Select an option

Save KentaGoto/d19661386db75203211bc7604eff3096 to your computer and use it in GitHub Desktop.
Go で Mail
package main
import gomail "gopkg.in/gomail.v2"
// https://godoc.org/gopkg.in/gomail.v2#example-package
func sendMail(from, to, cc, subject, body string) {
m := gomail.NewMessage()
m.SetHeader("From", from)
m.SetHeader("To", to)
m.SetHeader("Cc", cc)
m.SetHeader("Subject", subject)
m.SetBody("text/plain", body)
//m.Attach("test.jpg")
d := gomail.NewDialer("HOST_NAME", 25, "USER", "PASSWORD") // ホスト名, ポート, ユーザー, パスワード
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}
func main() {
// Mail情報
from := "<送信元>"
to := "<TO>"
cc := "<Cc>"
subject := "test: メール送信テスト"
body := "メール送信テスト"
// 送信
sendMail(from, to, cc, subject, body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment