From 9c44c7dcfac6d7ac6542b3106bf43a3f71d34d79 Mon Sep 17 00:00:00 2001 From: helei Date: Mon, 22 Sep 2025 21:04:28 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Eproxy.Dialer=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 9 +++++++++ smtp.go | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0e24271 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/helays/gomail/v2 + +go 1.25 + +require ( + golang.org/x/net v0.44.0 + gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc + gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df +) diff --git a/smtp.go b/smtp.go index 2aa49c8..6b73f14 100644 --- a/smtp.go +++ b/smtp.go @@ -8,6 +8,8 @@ import ( "net/smtp" "strings" "time" + + "golang.org/x/net/proxy" ) // A Dialer is a dialer to an SMTP server. @@ -33,6 +35,7 @@ type Dialer struct { // LocalName is the hostname sent to the SMTP server with the HELO command. // By default, "localhost" is sent. LocalName string + Dialer proxy.Dialer } // NewDialer returns a new SMTP Dialer. The given parameters are used to connect @@ -58,7 +61,16 @@ func NewPlainDialer(host string, port int, username, password string) *Dialer { // 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) + var ( + conn net.Conn + err error + ) + if d.Dialer != nil { + conn, err = d.Dialer.Dial("tcp", addr(d.Host, d.Port)) + } else { + conn, err = netDialTimeout("tcp", addr(d.Host, d.Port), 10*time.Second) + } + if err != nil { return nil, err } From bd03677c9e53b37b075d8be312d9399045a015c5 Mon Sep 17 00:00:00 2001 From: helei Date: Tue, 23 Sep 2025 14:23:25 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Eproxy.Dialer=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9c26cf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/go.work From b13863f6ce4016025e633d53a8081e68c5bc6511 Mon Sep 17 00:00:00 2001 From: helei Date: Tue, 23 Sep 2025 16:58:40 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Eproxy.Dialer=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smtp.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smtp.go b/smtp.go index 6b73f14..f3e9672 100644 --- a/smtp.go +++ b/smtp.go @@ -92,7 +92,7 @@ func (d *Dialer) Dial() (SendCloser, error) { if !d.SSL { if ok, _ := c.Extension("STARTTLS"); ok { - if err := c.StartTLS(d.tlsConfig()); err != nil { + if err = c.StartTLS(d.tlsConfig()); err != nil { c.Close() return nil, err } @@ -130,6 +130,7 @@ func (d *Dialer) tlsConfig() *tls.Config { if d.TLSConfig == nil { return &tls.Config{ServerName: d.Host} } + fmt.Printf("tlsConfig: %+v\n", d.TLSConfig) return d.TLSConfig } From 9c598c972cc02c4aeb367e149a12ad0f43505581 Mon Sep 17 00:00:00 2001 From: helei Date: Tue, 23 Sep 2025 17:11:02 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Eproxy.Dialer=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 0e24271..8675b04 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,5 @@ module github.com/helays/gomail/v2 -go 1.25 require ( golang.org/x/net v0.44.0 From b2c0157fce191c36bcd258a042fc97295025b992 Mon Sep 17 00:00:00 2001 From: helei Date: Tue, 23 Sep 2025 17:59:56 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Eproxy.Dialer=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smtp.go | 1 - 1 file changed, 1 deletion(-) diff --git a/smtp.go b/smtp.go index f3e9672..6729fa2 100644 --- a/smtp.go +++ b/smtp.go @@ -130,7 +130,6 @@ func (d *Dialer) tlsConfig() *tls.Config { if d.TLSConfig == nil { return &tls.Config{ServerName: d.Host} } - fmt.Printf("tlsConfig: %+v\n", d.TLSConfig) return d.TLSConfig }