Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store last SMTP code and message in Client #173

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type Client struct {

// Logger for all network activity.
DebugWriter io.Writer

// Last SMTP response
LastCode int
LastMsg string
}

// 30 seconds was chosen as it's the
Expand Down Expand Up @@ -207,9 +211,12 @@ func (c *Client) cmd(expectCode int, format string, args ...interface{}) (int, s
c.Text.StartResponse(id)
defer c.Text.EndResponse(id)
code, msg, err := c.Text.ReadResponse(expectCode)
c.LastCode = code
c.LastMsg = msg
if err != nil {
if protoErr, ok := err.(*textproto.Error); ok {
smtpErr := toSMTPErr(protoErr)
c.LastMsg = smtpErr.Message
return code, smtpErr.Message, smtpErr
}
return code, msg, err
Expand Down Expand Up @@ -457,10 +464,14 @@ func (d *dataCloser) Close() error {
}
return nil
} else {
_, _, err := d.c.Text.ReadResponse(250)
code, msg, err := d.c.Text.ReadResponse(250)
d.c.LastCode = code
d.c.LastMsg = msg
if err != nil {
if protoErr, ok := err.(*textproto.Error); ok {
return toSMTPErr(protoErr)
smtpErr := toSMTPErr(protoErr)
d.c.LastMsg = smtpErr.Message
return smtpErr
}
return err
}
Expand Down