1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-28 08:58:38 +02:00
authboss/defaults/log_mailer.go

44 lines
780 B
Go
Raw Normal View History

2018-01-29 23:14:55 +02:00
package defaults
import (
"bytes"
"context"
"io"
"github.com/volatiletech/authboss"
)
// LogMailer logs e-mails instead of sending them.
type LogMailer struct {
io.Writer
}
// NewLogMailer creates a mailer that doesn't deliver e-mails but
// simply logs them.
func NewLogMailer(writer io.Writer) *LogMailer {
return &LogMailer{writer}
}
// Send an e-mail
func (l LogMailer) Send(ctx context.Context, mail authboss.Email) error {
buf := &bytes.Buffer{}
data := struct {
Boundary string
Mail authboss.Email
}{
Boundary: "284fad24nao8f4na284f2n4",
Mail: mail,
}
err := emailTmpl.Execute(buf, data)
if err != nil {
return err
}
toSend := bytes.Replace(buf.Bytes(), []byte{'\n'}, []byte{'\r', '\n'}, -1)
_, err = l.Write(toSend)
return err
}