Skip to content

net/smtp: Proposal to add timeout argument to main functions #36209

Description

@cgarvie

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

all versions

Does this issue reproduce with the latest release?

yes

What did you do?

Attempt to use libraries which build upon net/SMTP, or use net/SMTP itself, in order to send emails over SMTP and you will quickly realize that having different allowed timeouts for different stages of the connection is not supported by default using net/SMTP. I have not explored using a custom Client as a workaround, but other standard libraries like Python's smtplib support timeouts by default as function arguments. and even using a custom Client doesn't seem like it would allow different timeouts for different stages of the SMTP process.

What did you expect to see?

c, err := smtp.Dial("mail.example.com:25", timeout_in_seconds)
if err != nil {
	log.Fatal(err)
}
...
_, err = fmt.Fprintf(wc, "This is the email body", timeout_in_seconds)
if err != nil {
	log.Fatal(err)
}
err = wc.Close(timeout_in_seconds)
if err != nil {
	log.Fatal(err)
}

What did you see instead?

c, err := smtp.Dial("mail.example.com:25")
if err != nil {
	log.Fatal(err)
}
...
_, err = fmt.Fprintf(wc, "This is the email body")
if err != nil {
	log.Fatal(err)
}
err = wc.Close()
if err != nil {
	log.Fatal(err)
}

If my suggested behavior is desired, I would be happy to make this improvement myself

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions