package main
import (
"gopkg.in/gomail.v2"
"sync"
)
type SesInfo struct {
Sender string
SenderName string
SmtpUser string
SmtpPass string
ConfigSet string
Host string
Port int
CharSet string
}
var sesInfo SesInfo
var once sync.Once
func init() {
once.Do(func() {
e = SesInfo{
Sender: "master@example.com",
SenderName: "Display name",
SmtpUser: "AWS SES ID",
SmtpPass: "AWS SES Password",
Host: "email-smtp.us-west-2.amazonaws.com",
Port: 587,
}
})
}
func Send(subject, body string, to []string) error {
m := gomail.NewMessage()
m.SetBody("text/html", body)
m.SetHeaders(map[string][]string{
"From": {m.FormatAddress(e.Sender, e.SenderName)},
"To": to,
"Subject": {subject},
"X-SES-CONFIGURATION-SET":{e.ConfigSet},
"X-SES-MESSAGE-TAGS": {"genre=test,genre2=test2"},
})
d := gomail.NewDialer(e.Host, e.Port, e.SmtpUser, e.SmtpPass)
if err := d.DialAndSend(m); err != nil {
return err
}
return nil
}