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

A BatchEmailListener performs batch sending of email over a single connection to the mail server. Like SMTPEmailSender, it implements EmailListener; but instead of sending email 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, for example, 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 email events reaches maxBatchSize. Also, if sendSchedule is specified, sends are performed according to the given schedule.

Oracle ATG Web Commerce 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.