Thread safety
scruper opened this issue · 4 comments
Hi! Is it thread save to invoke server.Connect on multiple "threads", or I need to create new server each time?
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.
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...
Yes, you can connect in multiple threads in that case. It's thread safe if KeepAlive is false.
Thank you !