go-mail / mail

Actively maintained fork of gomail. The best way to send emails in Go.
MIT License
464 stars 77 forks source link

Hanging Connection #67

Open MichaHoffmann opened 4 years ago

MichaHoffmann commented 4 years ago

The connection deadline is only set after smtpNewClient was called. Since smtpNewClient already wants to read 220 from the connection, a server that does not respond will result in a hanging connection.

This issue should be resolvable by moving the deadline code just after creation of the connection.

func (d *Dialer) Dial() (SendCloser, error) {
    conn, err := NetDialTimeout("tcp", addr(d.Host, d.Port), d.Timeout)
    if err != nil {
        return nil, err
    }

    if d.SSL {
        conn = tlsClient(conn, d.tlsConfig())
    }

    c, err := smtpNewClient(conn, d.Host)
    if err != nil {
        return nil, err
    }

    if d.Timeout > 0 {
        conn.SetDeadline(time.Now().Add(d.Timeout))
    }
afk11 commented 4 years ago

Duplicate of #49