A library for reliably sending emails from a Java application - with buffering, retrying, etc.

Sending emails from an application written in Java is not a big problem. Many types of software require this service to be reliable (at the application level → SMTP server). This implies that there is something like a buffer table with sending emails and some cyclic task for retrying later, if, for example, the SMTP server is unavailable, limit the number of messages sent per second or report persistent problems to the administrator.

I implemented this functionality in the main area in one project (it was not very complicated), but I wonder if there is any dedicated Java library that can be used for this purpose?

I did a search, but without any results ( vesijama , spring mail or commons mail , just simplify the preparation of the email message, but do not provide the specified functions).

+6
java email email-integration
source share
3 answers

All the problems you described are handled by the mail transfer agent (i.e. sendmail, postfix, Exchange, etc.) thanks to Good'Ole Days, when the Internet was designed to survive a nuclear war and 300 baud modems. There is no need for a library that adds them because they already exist.

All MTAs will buffer their messages in the spool file or in some other data store and automatically repeat any recoverable failures. This is required by RFC 2821 (section 4.5.4):

... while mail that cannot be sent immediately MUST be queued and periodically resent by the sender [...]

Repeats continue until the message is transmitted or the sender gives up; failure time should be at least 4-5 days. The parameters for the repeat algorithm MUST be customizable.

Any MTA is able to report problems that it encounters, it's just normal decency. They usually write to the syslog tool of the host operating system, which can be monitored in any number of ways.

I believe that not all of them implement speed limits, but a very quick Google search suggests that three of them that I mentioned can.

+3
source share

I will recommend Asprin to you.

Aspirin is an embedded, send-only SMTP server for Java developers.

+2
source share

Take a look at the OOP MailScheduler API . This library stores failed emails in the database by serializing objects. At the scheduled time, the main thread will select an e-mail from the SQL table and send it to the SMTP server. If communication with the SMTP server fails, the reverse flow will continue to send the email to the specified number.

0
source share

All Articles