5 Replies Latest reply on Oct 11, 2012 2:44 PM by Nitin Khare

    BatchEmailListener for sending emails

      Hi All,

      What are the required configurations that need to be done in order to send batch email using BatchEmailListener?
        • 1. Re: BatchEmailListener for sending emails
          Nitin Khare
          ATG provides a default BatchEmailListener component as /atg/dynamo/service/SMTPBatchEmail which you can use as email listener within your component for sending batch emails. You would be calling the sendEmailEvent() on SMTPBatchEmail component with the EmailEvent object as parameter just like you might already be doing with SMTPEmail. Both SMTPEmailSender (class for SMTPEmail component) and BatchEmailListener (class for SMTPBatchEmail component) implements EmailListener interface. SMTPBatchEmail has properties like emailMessageSender, maxBatchSize, scheduler, sendSchedule, collectDeadEmail and clearDeadEmailSchedule. A brief overview of these properties which you may configure based on your requirements:

          emailMessageSender: By default SMTPBatchEmail is configured to use SMTPEmail component through its emailMessageSender property so make sure your /atg/dynamo/service/SMTPEmail is also configured properly. If you were already using SMTPEmailSender for sending individual mails then it may be already set.

          maxBatchSize: The SMTPBatchEmail default configuration has no maxBatchSize specified (value=0) but if you specify a maxBatchSize value then a send is performed whenever the number of batched email events equals maxBatchSize value.

          scheduler: The scheduler is configured to use /atg/dynamo/service/Scheduler which usually you may not need to change.

          sendSchedule: It can be set to perform the send according to the given schedule. By default it is set to "every 3 minutes".

          collectDeadEmail: Boolean flag which defines if the SMTPBatchEmail component should internally keep undelivered mail in a dead email queue which you may want to examine and re-send later on. Default is false.

          clearDeadEmailSchedule: For specifying the schedule according to which the dead email queue will be cleared and used only if collectDeadEmail is set to true.

          On a related note, there is one EmailListenerQueue class which also implements EmailListener interface and it is exposed as component /atg/dynamo/service/SMTPEmailQueue. Any email message event sent to it are handled in a separate thread and added into a queue maintained by it. Then that queue itself is emptied using the /atg/dynamo/service/SMTPBatchEmail component.

          Edited by: Nitin Khare on Oct 4, 2012 12:48 AM
          • 2. Re: BatchEmailListener for sending emails
            I have done the following configurations for BatchEmail:

            (1) In my Java class i hve done the following config:

            (2) SMTPBatchEmail.properties:
            sendSchedule=every 2 min

            (3) SMTPEmail.properties:

            (4) SMTPEmailQueue.properties

            im giving list of recipients as my test email id, but im unable to receive any mail, im able to send mail on registeration...
            Do i need to make changes in initial.properties file.
            • 3. Re: BatchEmailListener for sending emails
              Nitin Khare
              As per your SMTPBatchEmail configuration:
              So make sure that you have 2 email events for send to occur
              sendSchedule=every 2 min
              Not sure if it was a typo but it should be every 2 minutes

              If all this is fine try setting loggingDebug to true for SMTPBatchEmail and SMTPEmailQueue components and see if you can get more information in the logs.
              • 4. Re: BatchEmailListener for sending emails
                Can I have a sample example for sending batch email with the required configurations and the classes required?
                • 5. Re: BatchEmailListener for sending emails
                  Nitin Khare
                  There is no other special configuration required than what has been already mentioned and it should work for you if you have understood and implemented it correctly. Here is a piece of pseudo code that should work.

                  Create a custom component and declare the dependency in the component configuration (properties file) on default SMTPEmailQueue component as:

                  Then in your custom component you can simply send EmailEvent to the listener like this:
                  private EmailListener emailListener;
                  public EmailListener getEmailListener()
                    return emailListener;
                  public void setEmailListener(EmailListener emailListener)
                    this.emailListener = emailListener;
                  public void sendBatchEmail() {
                    EmailEvent emlEv = new EmailEvent();
                    emlEv.setFrom ("atg-email-sender@example.com");
                    //emlEv.setRecipient ("test@example.com");
                    emlEv.setSubject ("Test e-mail");
                    em.setBody ("Sending a test e-mail.");
                    String [] recipients = {
                    emlEv.setRecipientList (recipients);
                  In case you want to create email with different recipient types (like cc, bcc), multipart messages or messages with attachments then you will have to create JavaMail's javax.mail.Message object for that and use that with EmailEvent object.