From 2babd40544a176cda759757c48bd54b46a9711c7 Mon Sep 17 00:00:00 2001 From: Nico Berlee Date: Sun, 17 Feb 2019 15:54:00 +0100 Subject: [PATCH] export SMTPError so it can be used in Send() to return custom smtp errors --- conn.go | 2 +- data.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/conn.go b/conn.go index fdd4de1..a4e9060 100644 --- a/conn.go +++ b/conn.go @@ -411,7 +411,7 @@ func (c *Conn) handleData(arg string) { err := c.User().Send(c.msg.From, c.msg.To, c.msg.Reader) io.Copy(ioutil.Discard, c.msg.Reader) // Make sure all the data has been consumed if err != nil { - if smtperr, ok := err.(*smtpError); ok { + if smtperr, ok := err.(*SMTPError); ok { code = smtperr.Code msg = smtperr.Message } else { diff --git a/data.go b/data.go index 8591e48..ae09f66 100644 --- a/data.go +++ b/data.go @@ -4,16 +4,17 @@ import ( "io" ) -type smtpError struct { +// SMTPError specifies the error code and message that needs to be returned to the client +type SMTPError struct { Code int Message string } -func (err *smtpError) Error() string { +func (err *SMTPError) Error() string { return err.Message } -var ErrDataTooLarge = &smtpError{ +var ErrDataTooLarge = &SMTPError{ Code: 552, Message: "Maximum message size exceeded", }