|
|
@@ -5,18 +5,28 @@ import (
|
|
|
)
|
|
|
|
|
|
type Smtp struct {
|
|
|
- Host string
|
|
|
- Port int
|
|
|
- Username, Password string
|
|
|
- Alias string
|
|
|
+ host string
|
|
|
+ port int
|
|
|
+ username, password string
|
|
|
+ alias string
|
|
|
+}
|
|
|
+
|
|
|
+func NewSmtp(host string, port int, username, password, alias string) *Smtp {
|
|
|
+ return &Smtp{
|
|
|
+ host: host,
|
|
|
+ port: port,
|
|
|
+ username: username,
|
|
|
+ password: password,
|
|
|
+ alias: alias,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func (self *Smtp) Send(to []string, subject, body string) error {
|
|
|
- m := gomail.NewMessage(/* gomail.SetEncoding(gomail.Base64) */)
|
|
|
- m.SetHeader("From", m.FormatAddress(self.Username, self.Alias))
|
|
|
+ m := gomail.NewMessage( /* gomail.SetEncoding(gomail.Base64) */ )
|
|
|
+ m.SetHeader("From", m.FormatAddress(self.username, self.alias))
|
|
|
m.SetHeader("To", to...)
|
|
|
m.SetHeader("Subject", subject)
|
|
|
- m.SetHeader("text/html", body)
|
|
|
+ m.SetBody("text/html", body)
|
|
|
//m.Attach("/tmp/foo.txt",
|
|
|
// gomail.Rename("foo.txt"),
|
|
|
// gomail.SetHeader(map[string][]string{
|
|
|
@@ -25,6 +35,6 @@ func (self *Smtp) Send(to []string, subject, body string) error {
|
|
|
// },
|
|
|
// }),
|
|
|
//)
|
|
|
- d := gomail.NewDialer(self.Host, self.Port, self.Username, self.Password)
|
|
|
+ d := gomail.NewDialer(self.host, self.port, self.username, self.password)
|
|
|
return d.DialAndSend(m)
|
|
|
}
|