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

Add ProxyDial to specify optional dialing to establish a transport connection. #58

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion smtp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mail

import (
"context"
"crypto/tls"
"fmt"
"io"
Expand All @@ -12,6 +13,9 @@ import (

// A Dialer is a dialer to an SMTP server.
type Dialer struct {
// ProxyDial specifies the optional dial function for
// establishing the transport connection.
DialProxy func(ctx context.Context, network, address string) (net.Conn, error)
// Host represents the host of the SMTP server.
Host string
// Port represents the port of the SMTP server.
Expand Down Expand Up @@ -53,6 +57,7 @@ type Dialer struct {
// to the SMTP server.
func NewDialer(host string, port int, username, password string) *Dialer {
return &Dialer{
DialProxy: (&net.Dialer{}).DialContext,
Host: host,
Port: port,
Username: username,
Expand All @@ -79,7 +84,8 @@ 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), d.Timeout)
ctx, _ := context.WithTimeout(context.Background(), d.Timeout)
conn, err := d.DialProxy(ctx, "tcp", addr(d.Host, d.Port))
if err != nil {
return nil, err
}
Expand Down