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

might be cool? #5

Closed
kristofer opened this issue Jan 7, 2014 · 5 comments
Closed

might be cool? #5

kristofer opened this issue Jan 7, 2014 · 5 comments

Comments

@kristofer
Copy link

Might be cool if the Send mech had a way to do this in a go routine? to avoid blocking code using the package?

I would think we need some community guidance about whether the go routines should inside the packages or expected to be done by the users of the package...

opinion?

@freeeve
Copy link

freeeve commented Jan 7, 2014

You could just call the relevant functions in a goroutine in the client code, right?

@jordan-wright
Copy link
Owner

I'm by no means an expert (and I hope someone with more knowledge can comment), but this is what I would do as well. I believe it would make it more difficult for people to use the library and catch the error if it was run as a goroutine internally.

I'll keep the issue open until (hopefully) we get a couple more responses.

@dcoxall
Copy link

dcoxall commented Jan 8, 2014

You're right. The correct way would be to let the client code decide:

e := email.NewEmail()
// Setup email
go e.Send("smtp.gmail.com:587", smtp.PlainAuth("", "test@gmail.com", "password123", "smtp.gmail.com"))

Or you can of course create your own function for it:

func sendEmail(e *email.Email) {
    e.Send("smtp.gmail.com:587", smtp.PlainAuth("", "test@gmail.com", "password123", "smtp.gmail.com"))
}

func main() {
    e := email.NewEmail()
    // Setup email
    go sendEmail(e)
}

This is just pseudo code. I haven't tested it but I think it should work

@jordan-wright
Copy link
Owner

It appears the consensus is to do it via client code. I agree, as this will help keep the Send() function easy to implement and maintain. It should be noted that, again, Send() is not at all the only way to send an email. The important part of this package is the type management and the Bytes() function, which does a lot of leg work.

Feel free to reopen as needed, but for now I am going to consider this issue to be closed.

Thanks again for bringing this up, and to everyone for the input.

@arkn98
Copy link

arkn98 commented Jun 26, 2020

Sorry for opening this up again. I'm working on some email-critical functionality. Currently to know whether a Send(...) failed (so that I can retry sending it again), I've to wait for it to return, which is long. Going by @dcoxall's suggestion, with the goroutine I'm ignoring the returned error.

So, is there some suggested way to run Send(...) inside a goroutine and predictably know whether it failed (for the purposes of resending)?

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

5 participants