| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package utl
- import (
- "gopkg.in/gomail.v2"
- )
- type Smtp struct {
- 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.SetHeader("To", to...)
- m.SetHeader("Subject", subject)
- m.SetBody("text/html", body)
- //m.Attach("/tmp/foo.txt",
- // gomail.Rename("foo.txt"),
- // gomail.SetHeader(map[string][]string{
- // "Content-Disposition": []string{
- // fmt.Sprintf(`attachment; filename="%s"`, mime.QEncoding.Encode("UTF-8", name)),
- // },
- // }),
- //)
- d := gomail.NewDialer(self.host, self.port, self.username, self.password)
- return d.DialAndSend(m)
- }
|