Skip to content

Commit 36a92f2

Browse files
committed
client: save greet error
(cherry picked from commit b63eede)
1 parent 591442c commit 36a92f2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

client.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ type Client struct {
2929
lmtp bool
3030
ext map[string]string // supported extensions
3131
localName string // the name to use in HELO/EHLO/LHLO
32-
didHello bool // whether we've said HELO/EHLO/LHLO
3332
didGreet bool // whether we've received greeting from server
33+
greetError error // the error from the greeting
34+
didHello bool // whether we've said HELO/EHLO/LHLO
3435
helloError error // the error from the hello
3536
rcpts []string // recipients accumulated for the current session
3637

@@ -181,21 +182,21 @@ func (c *Client) Close() error {
181182

182183
func (c *Client) greet() error {
183184
if c.didGreet {
184-
return nil
185+
return c.greetError
185186
}
186187

187188
// Initial greeting timeout. RFC 5321 recommends 5 minutes.
188189
c.conn.SetDeadline(time.Now().Add(c.CommandTimeout))
189190
defer c.conn.SetDeadline(time.Time{})
190191

192+
c.didGreet = true
191193
_, _, err := c.readResponse(220)
192194
if err != nil {
195+
c.greetError = err
193196
c.text.Close()
194-
return err
195197
}
196198

197-
c.didGreet = true
198-
return nil
199+
return c.greetError
199200
}
200201

201202
// hello runs a hello exchange if needed.
@@ -204,12 +205,11 @@ func (c *Client) hello() error {
204205
return c.helloError
205206
}
206207

207-
c.didHello = true
208208
if err := c.greet(); err != nil {
209-
c.helloError = err
210-
return c.helloError
209+
return err
211210
}
212211

212+
c.didHello = true
213213
if err := c.ehlo(); err != nil {
214214
var smtpError *SMTPError
215215
if errors.As(err, &smtpError) && (smtpError.Code == 500 || smtpError.Code == 502) {

0 commit comments

Comments
 (0)