Seeing is believing! First of all, please enjoy the example of Bento framework that is running on our web site. It is the simple photo Blog where you can upload the image files by your web browser (multipart/form-data), or e-mail with file attachment. After you grasp how it works, please explore its source code. The source code of the example is included in the FREE trial version of Bento framework.
| [ Try and download example ... ] |
BulkEmailSender is Java API to send the bulk e-mail at the scheduled time. It queues a list of recipients into the SQL tables, and the background Thread picks up them at the scheduled time. In case of failure with the SMTP connection, the background Thread will retry up to the specified time.
There are many tools to send the bulk e-mails in the world, but most of them are developed for the specific SMTP server. In contrast, this API can be used with any SMTP servers through JavaMail API. If you need to make your system portable across the environments, BulkEmailSender will be the best solution.
BulkEmailSender implements very simple programming interface. To queue the bulk e-mail, just a single method call will be enough. It is either of:
If you have SQL tables that store the list of recipients, the first one will be enough. As its 3rd parameter, you can pass the SQL statement that selects the recipients and inserts them into the SQL table of this API. Or, if you have the list of recipients as a set of List, you can pass them to the second one.
Please note that both of these methods return soon, without establishing the connection with the SMTP server, even if you have millions of recipients.
As mentioned above, the method to queue the bulk e-mail returns soon. A set of background Threads in BulkEmailSender take charge of the connection with SMTP servers. On the test environment below, it takes about 90 seconds to queue a 1000 characters e-mail to 1000 recipients:
| Consumer Threads | 3 |
| SMTP server | qmail running on localhost |
| SQL database | MySQL running on localhost |
| CPU | CELERON-2 1.4 GHZ |
| Memory | 512MB PC133 SDRAM |
You may need to shutdown your application server while the background Threads in BulkEmailSender are talking with SMTP servers. In this case, BulkEmailSender terminates the background Threads. At this point, BulkEmailSender records the last recipient to which the e-mail was sent. When you start your application server again, BulkEmailSender dispatches the background Threads, and these Threads start from the next recipient. By this way, you can be sure that the scheduled e-mail will be sent to all the recipients even if your application server is restarted while BulkEmailSender is working.
BulkEmailSender can use multiple SMTP servers to send the bulk e-mail. To use the best of the available resources, this API implements Producer / Consumer design. There is always only one Producer Thread. But the number of Consumer Threads equals to the number of the available SMTP server, i.e. one Consumer Thread will be created for each SMTP server. When a Producer Thread selects a series of recipients from the SQL table, each recipient is put into ArrayBlockingQueue one by one. Then, a free Consumer Thread takes one recipient from ArrayBlockingQueue and connects to its SMTP server to queue the e-mail. As soon as the e-mail is queued, the Consumer Thread takes another recipient from ArrayBlockingQueue. As a result, the Consumer Thread with the high performance SMTP server will send more e-mails than the Consumer Thread with the poor performance SMTP server. By this way, this API can use the best of your resource.
To see what are happening behind it, please set debug=true in the property file of BulkEmailSender and investigate the log.
| [ Source code example 01 ... ] |
| [ Source code example 02 ... ] |
As you see in those example source codes, only a few lines of code will be enough for your Servlet / JSP to send bulk e-mail through multiple SMTP servers.
You can read the Java doc for this API online. Or it is included in the trial version of this API and you can download it at FREE.
| Java doc | README |
| Trial License | Product License (PDF) |
| Download | |
Copyright © 1997-2008 OOP-Research CorporationTM, All Rights Reserved.