Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/go.work
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/helays/gomail/v2


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
)
16 changes: 14 additions & 2 deletions smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/smtp"
"strings"
"time"

"golang.org/x/net/proxy"
)

// A Dialer is a dialer to an SMTP server.
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -80,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
}
Expand Down