|
|
@@ -4,15 +4,19 @@ import (
|
|
|
"gopkg.in/gomail.v2"
|
|
|
)
|
|
|
|
|
|
-type Smtp struct {
|
|
|
+type IMessager interface {
|
|
|
+ Send([]string, string, string) error
|
|
|
+}
|
|
|
+
|
|
|
+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{
|
|
|
+func NewSmtp(host string, port int, username, password, alias string) IMessager {
|
|
|
+ return &smtp{
|
|
|
host: host,
|
|
|
port: port,
|
|
|
username: username,
|
|
|
@@ -21,7 +25,7 @@ func NewSmtp(host string, port int, username, password, alias string) *Smtp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (self *Smtp) Send(to []string, subject, body string) error {
|
|
|
+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...)
|
|
|
@@ -38,3 +42,13 @@ func (self *Smtp) Send(to []string, subject, body string) error {
|
|
|
d := gomail.NewDialer(self.host, self.port, self.username, self.password)
|
|
|
return d.DialAndSend(m)
|
|
|
}
|
|
|
+
|
|
|
+type disableMessager struct{}
|
|
|
+
|
|
|
+func NewDisableMessager() IMessager {
|
|
|
+ return &disableMessager{}
|
|
|
+}
|
|
|
+
|
|
|
+func (self *disableMessager) Send(to []string, subject, body string) error {
|
|
|
+ return nil
|
|
|
+}
|