github.com/volatiletech/authboss@v2.4.1+incompatible/defaults/log_mailer.go (about) 1 package defaults 2 3 import ( 4 "bytes" 5 "context" 6 "io" 7 8 "github.com/volatiletech/authboss" 9 ) 10 11 // LogMailer logs e-mails instead of sending them. 12 type LogMailer struct { 13 io.Writer 14 } 15 16 // NewLogMailer creates a mailer that doesn't deliver e-mails but 17 // simply logs them. 18 func NewLogMailer(writer io.Writer) *LogMailer { 19 return &LogMailer{writer} 20 } 21 22 // Send an e-mail 23 func (l LogMailer) Send(ctx context.Context, mail authboss.Email) error { 24 buf := &bytes.Buffer{} 25 26 data := struct { 27 Boundary string 28 Mail authboss.Email 29 }{ 30 Boundary: "284fad24nao8f4na284f2n4", 31 Mail: mail, 32 } 33 34 err := emailTmpl.Execute(buf, data) 35 if err != nil { 36 return err 37 } 38 39 toSend := bytes.Replace(buf.Bytes(), []byte{'\n'}, []byte{'\r', '\n'}, -1) 40 41 _, err = l.Write(toSend) 42 return err 43 }