|
@@ -204,32 +204,58 @@ func addAuth(c *client, auth smtp.Auth) (bool, error) {
|
|
return true, nil
|
|
return true, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (p *Pool) build() (*client, error) {
|
|
|
|
- cl, err := smtp.Dial(p.addr)
|
|
|
|
|
|
+func (p *Pool) build() (*client, error) { //修改逻辑为tls
|
|
|
|
+
|
|
|
|
+ conn, err := tls.Dial("tcp", p.addr, p.tlsConfig)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- // Is there a custom hostname for doing a HELLO with the SMTP server?
|
|
|
|
- if p.helloHostname != "" {
|
|
|
|
- cl.Hello(p.helloHostname)
|
|
|
|
|
|
+ c, err := smtp.NewClient(conn, p.tlsConfig.ServerName)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
}
|
|
}
|
|
-
|
|
|
|
- c := &client{cl, 0}
|
|
|
|
-
|
|
|
|
- if _, err := startTLS(c, p.tlsConfig); err != nil {
|
|
|
|
|
|
+ if err = c.Hello("localhost"); err != nil {
|
|
c.Close()
|
|
c.Close()
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
if p.auth != nil {
|
|
if p.auth != nil {
|
|
- if _, err := addAuth(c, p.auth); err != nil {
|
|
|
|
- c.Close()
|
|
|
|
- return nil, err
|
|
|
|
|
|
+ if ok, _ := c.Extension("AUTH"); ok {
|
|
|
|
+ if err = c.Auth(p.auth); err != nil {
|
|
|
|
+ c.Close()
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return c, nil
|
|
|
|
|
|
+ return &client{c, 0}, nil
|
|
|
|
+
|
|
|
|
+ // cl, err := smtp.Dial(p.addr)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // return nil, err
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // // Is there a custom hostname for doing a HELLO with the SMTP server?
|
|
|
|
+ // if p.helloHostname != "" {
|
|
|
|
+ // cl.Hello(p.helloHostname)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // c := &client{cl, 0}
|
|
|
|
+
|
|
|
|
+ // if _, err := startTLS(c, p.tlsConfig); err != nil {
|
|
|
|
+ // c.Close()
|
|
|
|
+ // return nil, err
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // if p.auth != nil {
|
|
|
|
+ // if _, err := addAuth(c, p.auth); err != nil {
|
|
|
|
+ // c.Close()
|
|
|
|
+ // return nil, err
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // return c, nil
|
|
}
|
|
}
|
|
|
|
|
|
func (p *Pool) maybeReplace(err error, c *client) {
|
|
func (p *Pool) maybeReplace(err error, c *client) {
|