Each time an SMTPEmailSender is used to send an EmailEvent, an SMTP connection is opened to the mail server, the e-mail is sent, and the connection is closed. A new SMTP connection is opened and closed every time an e-mail is sent, even if you are calling sendEmailEvent continuously to send multiple e-mail messages. This can be costly and unnecessary if many messages need to be sent at once.

A BatchEmailListener performs batch sending of e-mail over a single connection to the mail server. Like SMTPEmailSender, it implements EmailListener; but instead of sending e-mail after receiving each EmailEvent, it collects the EmailEvent objects and periodically sends the messages out in batches. The emailMessageSender property points to the component that actually performs the message sending, e.g., SMTPEmail.

Two properties of BatchEmailListener control how often the batch sends are performed, maxBatchSize and sendSchedule. If maxBatchSize is specified, a send is performed whenever the number of batched e-mail events reaches maxBatchSize. Also, if sendSchedule is specified, sends are performed according to the given schedule.

Dynamo comes with an instance of BatchEmailListener at /atg/dynamo/service/SMTPBatchEmail. This batch listener points to SMTPEmail as its emailMessageSender. The default configuration has no maxBatchSize, and a sendSchedule which calls for a send to be performed every 3 minutes.

 
loading table of contents...