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

net/smtp: unable to retrieve SMTP server response error information after EHLO command in (*Client).hello() function #56125

Open
liangxj8 opened this issue Oct 10, 2022 · 1 comment
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@liangxj8
Copy link

liangxj8 commented Oct 10, 2022

What version of Go are you using (go version)?

$ go 1.12.7

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOHOSTARCH="amd64"
GOHOSTOS="darwin"

What did you do?

send email using a non-whitelist ip address

What did you expect to see?

function smtp.SendMail return the real error {"Code": 117, "Msg": "The IP Address is not whitelisted: x.x.x.x"} from (*Client).ehlo()

What did you see instead?

function smtp.SendMail return the error EOF from (*Client).helo()

Proposal

Before

The comment of (*Client).helo() is helo sends the HELO greeting to the server. It should be used only when the server does not support ehlo., but in (*Client) hello() the implement is:

// hello runs a hello exchange if needed.
func (c *Client) hello() error {
	if !c.didHello {
		c.didHello = true
		err := c.ehlo()
		if err != nil {
			c.helloError = c.helo()
		}
	}
	return c.helloError
}

When we get a error from (*Client).helo() not only 502 (permitted only with an old-style server that does not support EHLO) (see 4.3.2 Command-Reply Sequences), the c.helo() will still execute and return another error like EOF what I got. When we print error like "EOF" in log, we cannot get any thing helpful to debug.

After

// hello runs a hello exchange if needed.
func (c *Client) hello() error {
   if !c.didHello {
   	c.didHello = true
   	c.helloError = c.ehlo()
   	if c.helloError != nil && c.helloError.(*textproto.Error).Code == 502 {
   		c.helloError = c.helo()
   	}
   }
   return c.helloError
}
@liangxj8 liangxj8 changed the title net/smtp: Unable to retrieve SMTP server response error information after EHLO command in (*Client).hello() function proposal: net/smtp: Unable to retrieve SMTP server response error information after EHLO command in (*Client).hello() function Oct 10, 2022
@gopherbot gopherbot added this to the Proposal milestone Oct 10, 2022
@ianlancetaylor
Copy link
Contributor

There doesn't seem to be an API change here, so I don't think this has to be a proposal. This looks more like a bug fix (though I don't know whether it is the right thing to do). Taking this issue out of the proposal process.

@ianlancetaylor ianlancetaylor changed the title proposal: net/smtp: Unable to retrieve SMTP server response error information after EHLO command in (*Client).hello() function net/smtp: unable to retrieve SMTP server response error information after EHLO command in (*Client).hello() function Oct 12, 2022
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. help wanted and removed Proposal labels Oct 12, 2022
@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Backlog Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants