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

Not possible to configure timeouts with this library #102

Open
codestation opened this issue Mar 10, 2020 · 1 comment
Open

Not possible to configure timeouts with this library #102

codestation opened this issue Mar 10, 2020 · 1 comment

Comments

@codestation
Copy link

codestation commented Mar 10, 2020

If the SMTP server isn't available then isn't possible to close the pool connections because it hangs indefinitely on net.Dial

package main

import (
        "fmt"
        "net/smtp"
        "time"

        "github.com/jordan-wright/email"
)

func main() {
        e := email.NewEmail()
        e.From = "Jordan Wright <[email protected]>"
        e.To = []string{"[email protected]"}
        e.Bcc = []string{"[email protected]"}
        e.Cc = []string{"[email protected]"}
        e.Subject = "Awesome Subject"
        e.Text = []byte("Text Body is, of course, supported!")
        e.HTML = []byte("<h1>Fancy HTML is supported, too!</h1>")

        p, err := email.NewPool("smtp.gmail.com:65535", 1, smtp.PlainAuth("", "[email protected]", "password123", "smtp.gmail.com"))
        if err != nil {
                panic(err)
        }
        err = p.Send(e, 1*time.Second)
        if err != nil {
                fmt.Println(err)
        }
        // hangs here because it never opened the connection
        p.Close()
}

For example the above code never exits because it uses a port where the server isn't listening.

IMO, a custom Dialer should be accepted so one can configure various timeouts to prevent this scenario.

@xhit
Copy link

xhit commented Mar 17, 2020

The package go-simple-mail https://github.com/xhit/go-simple-mail resolves this issue.

Feel free to adapt the method used in go-simple-mail for connection timeout and send timeout for this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants