|
@@ -4,29 +4,27 @@ import (
|
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
-
|
|
|
- "git.dmitriygnatenko.ru/dima/go-common/smtp"
|
|
|
)
|
|
|
|
|
|
type EmailWriter struct {
|
|
|
- recipient string
|
|
|
- subject string
|
|
|
- smtp *smtp.SMTP
|
|
|
+ recipient string
|
|
|
+ subject string
|
|
|
+ smtpClient SMTPClient
|
|
|
}
|
|
|
|
|
|
-func NewEmailWriter(smtp *smtp.SMTP, recipient string, subject string) (*EmailWriter, error) {
|
|
|
+func NewEmailWriter(smtpClient SMTPClient, recipient string, subject string) (*EmailWriter, error) {
|
|
|
if len(recipient) == 0 {
|
|
|
return nil, errors.New("empty recipient")
|
|
|
}
|
|
|
|
|
|
- if smtp == nil {
|
|
|
+ if smtpClient == nil {
|
|
|
return nil, errors.New("empty smtp client")
|
|
|
}
|
|
|
|
|
|
return &EmailWriter{
|
|
|
- recipient: recipient,
|
|
|
- subject: subject,
|
|
|
- smtp: smtp,
|
|
|
+ recipient: recipient,
|
|
|
+ subject: subject,
|
|
|
+ smtpClient: smtpClient,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
@@ -37,6 +35,6 @@ func (w EmailWriter) Write(p []byte) (int, error) {
|
|
|
return 0, err
|
|
|
}
|
|
|
|
|
|
- err := w.smtp.Send(w.recipient, w.subject, out.String(), false)
|
|
|
+ err := w.smtpClient.Send(w.recipient, w.subject, out.String(), false)
|
|
|
return 0, err
|
|
|
}
|