go-simple-mail icon indicating copy to clipboard operation
go-simple-mail copied to clipboard

Improvement: Reuse Connection (or unclear documentation)

Open thedustin opened this issue 4 years ago • 3 comments

Hey, first things first: nice package, thank you for that. But it seems that it is not really possible to keep one connection open?

I want to run this in the background and from time to time send a mail. As far as I understood the documentation (or sadly/more precisely the code 😬) right, it is not intended to reuse a client? Instead I should create a new client for each message (or hope that the connection is still open/use client.noop and maybe re-create the client)? This seems a bit wasteful to open a new connection for every message.

Maybe this could be an improvement for v3? 😁

thedustin avatar Feb 27 '22 11:02 thedustin

Hi Dusting.

It's possible reuse the connection, but currently is left to the developer to implement the same connection, here a comment explaining how this should be: https://github.com/xhit/go-simple-mail/issues/23#issuecomment-752015639

And yes, I want to add this in the package because the implementation require knowledge of how works SMTP protocol, I hope have a time in next days to implement it in v2 because it should not be a breaking change.

xhit avatar Feb 28 '22 16:02 xhit

is it safe to use single connection in multiple goroutines?

rtanx avatar Aug 04 '22 04:08 rtanx

@rtanx it's safe always you not send a new operation while another operation is in process, see https://github.com/xhit/go-simple-mail/issues/23#issuecomment-752015639

xhit avatar Aug 04 '22 15:08 xhit