Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from ivy/export-net-dial-timeout
Browse files Browse the repository at this point in the history
Export NetDialTimeout
  • Loading branch information
pedromorgan authored Dec 6, 2017
2 parents 594fad0 + 8340910 commit ab8dca3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ 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
// 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
}
Expand Down Expand Up @@ -182,9 +187,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)
}
)
Expand Down
2 changes: 1 addition & 1 deletion smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ab8dca3

Please sign in to comment.