Documentation ¶
Overview ¶
emailsender package provides email senders.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
WrongEmailValue = errors.New("Wrong email value (missing recipient or nil template)")
)
Functions ¶
This section is empty.
Types ¶
type BatchSender ¶
type BatchSender struct {
// contains filtered or unexported fields
}
BatchSender is a sender that stores emails in a queue to send them asynchronously in batch. Emails from the queue are sent while the connections is opened. The connection is opened once the number of waiting emails reach a threshold or when an email is in the queue for at least a given duration. The connection is closed as soon as there is no waiting email in the queue.
func StartBatchSender ¶
func StartBatchSender(options BatchSenderOptions) (sender *BatchSender, err error)
StartBatchSender creates, starts and returns a new BatchSender.
func (*BatchSender) Close ¶
func (self *BatchSender) Close() error
Close asks the sender to send all the emails in the queue and then to stop the background goroutine.
func (*BatchSender) Send ¶
func (self *BatchSender) Send(email Email) error
Send adds an email to the queue.
type BatchSenderOptions ¶
type BatchSenderOptions struct { MinBatchLen int MaxDelay string // string representation of a duration Sender string // email address SMTP string // host:port }
BatchSenderOptions records the options for the batch sender. An email is sent by the batch sender either if there are at least (MinBatchLen - 1) other emails waiting for being sent, or if the email is wainting to be sent for at least MaxDelay.
type DirectSender ¶
type DirectSender struct { Sender string // email address SMTP string // host:port // contains filtered or unexported fields }
DirectSender is a sender that directly sends emails to an SMTP server. The connection to the server is left open for multiple emails to be send in one session.
func (*DirectSender) Close ¶
func (self *DirectSender) Close() error
func (*DirectSender) Quit ¶
func (self *DirectSender) Quit() error
Quit closes the currently opened connection, if any. It should be called as soon as there is no email to send.
func (*DirectSender) Send ¶
func (self *DirectSender) Send(email Email) (err error)
Send sends an email to the SMTP server. It opens a new connection if needed, otherwise it uses the previously opened connection.
type Email ¶
Email represents an email to be sent.
The real email (both its header and its body) is constructed by the Sender by applying the provided template to the provided data.