I'm writing a package which I intend to make one initial connection to the local SMTP server and then it waits on a channel which will be populated with emails to send when they are needed to be sent.
Looking at net/http it appears to be expecting that the SMTP server should be dialed into and authenticated each time an email is to be sent. Surely I can dial and authenticate once, keep the connection open and just add new emails as they come?
Looking at the source for smtp.SendMail
, I don't see how this can be done, as there does not appear to be a way to recycle the *Client
:
http://golang.org/src/net/smtp/smtp.go?s=7610:7688#L263
There is a Reset
function for *Client
, but the description for that is:
Reset sends the RSET command to the server, aborting the current mail transaction.
I don't want to abort the current mail transaction, I want to have multiple mail transactions.
How can I keep the connection to the SMTP server open and send multiple emails on that one connection?