Last active
December 24, 2019 08:00
-
-
Save KentaGoto/d19661386db75203211bc7604eff3096 to your computer and use it in GitHub Desktop.
Go で Mail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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