From f10eb0a0f403519243d2b9cdce13eb60d8a8aa43 Mon Sep 17 00:00:00 2001 From: Andras Elso Date: Sun, 8 Oct 2017 14:04:37 +0200 Subject: [PATCH 1/2] Export NetDialTimeout to public [Ivy: move NetDialTimeout outside of var stubs to prevent confusion] --- smtp.go | 9 +++++---- smtp_test.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/smtp.go b/smtp.go index 2aa49c8..12d0606 100644 --- a/smtp.go +++ b/smtp.go @@ -55,10 +55,12 @@ func NewPlainDialer(host string, port int, username, password string) *Dialer { return NewDialer(host, port, username, password) } +var NetDialTimeout = net.DialTimeout + // Dial dials and authenticates to an SMTP server. The returned SendCloser // should be closed when done using it. func (d *Dialer) Dial() (SendCloser, error) { - conn, err := netDialTimeout("tcp", addr(d.Host, d.Port), 10*time.Second) + conn, err := NetDialTimeout("tcp", addr(d.Host, d.Port), 10*time.Second) if err != nil { return nil, err } @@ -182,9 +184,8 @@ func (c *smtpSender) Close() error { // Stubbed out for tests. var ( - netDialTimeout = net.DialTimeout - tlsClient = tls.Client - smtpNewClient = func(conn net.Conn, host string) (smtpClient, error) { + tlsClient = tls.Client + smtpNewClient = func(conn net.Conn, host string) (smtpClient, error) { return smtp.NewClient(conn, host) } ) diff --git a/smtp_test.go b/smtp_test.go index b6f9155..3323029 100644 --- a/smtp_test.go +++ b/smtp_test.go @@ -248,7 +248,7 @@ func doTestSendMail(t *testing.T, d *Dialer, want []string, timeout bool) { timeout: timeout, } - netDialTimeout = func(network, address string, d time.Duration) (net.Conn, error) { + NetDialTimeout = func(network, address string, d time.Duration) (net.Conn, error) { if network != "tcp" { t.Errorf("Invalid network, got %q, want tcp", network) } From 834091045ffc7628973edbd31a3f49afb9a5d5ca Mon Sep 17 00:00:00 2001 From: Ivy Evans Date: Wed, 6 Dec 2017 12:39:09 -0800 Subject: [PATCH 2/2] Document NetDialTimeout --- smtp.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/smtp.go b/smtp.go index 12d0606..b523f15 100644 --- a/smtp.go +++ b/smtp.go @@ -55,6 +55,9 @@ func NewPlainDialer(host string, port int, username, password string) *Dialer { return NewDialer(host, port, username, password) } +// NetDialTimeout specifies the DialTimeout function to establish a connection +// to the SMTP server. This can be used to override dialing in the case that a +// proxy or other special behavior is needed. var NetDialTimeout = net.DialTimeout // Dial dials and authenticates to an SMTP server. The returned SendCloser