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

Thread safety #42

Closed
scruper opened this issue Jul 8, 2021 · 4 comments
Closed

Thread safety #42

scruper opened this issue Jul 8, 2021 · 4 comments

Comments

@scruper
Copy link

scruper commented Jul 8, 2021

Hi! Is it thread save to invoke server.Connect on multiple "threads", or I need to create new server each time?

@xhit
Copy link
Owner

xhit commented Jul 8, 2021

You can connect every time in same thread if KeepAlive is false (by default) because the connection closes after email is sent.

If you want to use a lot of connections to SMTP server and send in bulk, you can follow #23 to use KeepAlive, and NOOP.

@scruper
Copy link
Author

scruper commented Jul 8, 2021

But what if I want to connect in multiple threads. For example, I need to send a verification email for each connected user (via HTTP) and each HTTP connection is in a separate goroutine. Of course, I can use a channel and connect in a single goroutine...

@xhit
Copy link
Owner

xhit commented Jul 8, 2021

Yes, you can connect in multiple threads in that case. It's thread safe if KeepAlive is false.

@scruper
Copy link
Author

scruper commented Jul 8, 2021

Thank you !

@scruper scruper closed this as completed Jul 8, 2021
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