diff --git a/mail/smtp.go b/mail/smtp.go index 9dc93fd..b63871f 100644 --- a/mail/smtp.go +++ b/mail/smtp.go @@ -3,29 +3,28 @@ package mail import ( "crypto/tls" "github.com/argcv/stork/config" - "gopkg.in/gomail.v2" + "github.com/go-mail/mail" "io" "sync" "time" ) -// for future update, -// please refer to this example: -// https://github.com/go-gomail/gomail/blob/master/example_test.go#L1 +// active fork +// https://github.com/go-mail/mail type SMTPSession struct { - Dialer *gomail.Dialer + Dialer *mail.Dialer Config *config.SMTPConfig isClosed bool closeSch *SMTPCloseSch - sendCloser gomail.SendCloser + sendCloser mail.SendCloser } func (s *SMTPSession) NewMessage() (*SMTPMessage) { m := &SMTPMessage{ Dialer: s.Dialer, Config: s.Config, - Message: gomail.NewMessage(), + Message: mail.NewMessage(), locker: &sync.Mutex{}, ss: s, @@ -34,7 +33,7 @@ func (s *SMTPSession) NewMessage() (*SMTPMessage) { return m } -func (s *SMTPSession) Dial(f func(gomail.SendCloser) error) error { +func (s *SMTPSession) Dial(f func(mail.SendCloser) error) error { s.closeSch.Activate() err := s.closeSch.SafeExec(func() error { if s.isClosed { @@ -64,7 +63,7 @@ func (s *SMTPSession) close() error { } func NewSMTPSession(c config.SMTPConfig) (s *SMTPSession, err error) { - dialer := gomail.NewDialer(c.Host, c.Port, c.User, c.Pass) + dialer := mail.NewDialer(c.Host, c.Port, c.User, c.Pass) if c.Option.InsecureSkipVerify { dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true} } @@ -82,8 +81,8 @@ func NewSMTPSession(c config.SMTPConfig) (s *SMTPSession, err error) { } type SMTPMessage struct { - Dialer *gomail.Dialer - Message *gomail.Message + Dialer *mail.Dialer + Message *mail.Message Config *config.SMTPConfig locker *sync.Mutex @@ -148,7 +147,7 @@ func (m *SMTPMessage) HtmlBody(body string) *SMTPMessage { func (m *SMTPMessage) Attach(path string, name ...string) *SMTPMessage { if len(name) > 0 { - m.Message.Attach(path, gomail.Rename(name[0])) + m.Message.Attach(path, mail.Rename(name[0])) } else { m.Message.Attach(path) } @@ -156,7 +155,7 @@ func (m *SMTPMessage) Attach(path string, name ...string) *SMTPMessage { } func (m *SMTPMessage) AttachBytes(name string, data []byte) *SMTPMessage { - m.Message.Attach(name, gomail.SetCopyFunc(func(w io.Writer) error { + m.Message.Attach(name, mail.SetCopyFunc(func(w io.Writer) error { _, err := w.Write(data) return err })) @@ -187,7 +186,7 @@ func (m *SMTPMessage) AddToHeader(field string, value ...string) *SMTPMessage { return m } -func (m *SMTPMessage) AddAlternative(contentType, body string, settings ...gomail.PartSetting) *SMTPMessage { +func (m *SMTPMessage) AddAlternative(contentType, body string, settings ...mail.PartSetting) *SMTPMessage { m.Message.AddAlternative(contentType, body, settings...) return m } @@ -205,14 +204,14 @@ func (m *SMTPMessage) FormatAddress(address, name string) string { // return locker //} -func (m *SMTPMessage) SetBody(contentType, body string, settings ...gomail.PartSetting) *SMTPMessage { +func (m *SMTPMessage) SetBody(contentType, body string, settings ...mail.PartSetting) *SMTPMessage { m.Message.SetBody(contentType, body, settings...) return m } func (m *SMTPMessage) Perform() error { - return m.ss.Dial(func(s gomail.SendCloser) (err error) { - err = gomail.Send(s, m.Message) + return m.ss.Dial(func(s mail.SendCloser) (err error) { + err = mail.Send(s, m.Message) if err != nil { m.ss.close() }