Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this questionSending emails from an application written in Java is not a big problem. In many kinds of software it is required to have that service reliable (at application -> SMTP server connection level). This implicates having something like a buffer table with emails to send and some cyclic job to retry later if for example SMTP server is unavailable, limit number of sending message per second or report permanent problems to the administrator.
I implemented that functionality in a basic scope in one project (wasn't very complicated), but I wonder if there is any dedicated Java library which could be reused for that purpose?
I did some search, but without any results (vesijama, spring mail or commons mail just make it easy to prepare email message, but doesn't pr开发者_StackOverflow社区ovide mentioned features).
All of the concerns you describe are handled by the mail transfer agent (i.e. sendmail, postfix, Exchange, etc) thanks to the Good 'Ole Days when the Internet was designed to survive nuclear war and 300 baud modems. There is no need for a library that adds them, because they're already there.
All MTA's will buffer their messages in a spool file or some other data store and automatically retry any recoverable failures. This is required by RFC 2821 (Section 4.5.4):
...while mail that cannot be transmitted immediately MUST be queued and periodically retried by the sender [...]
Retries continue until the message is transmitted or the sender gives up; the give-up time generally needs to be at least 4-5 days. The parameters to the retry algorithm MUST be configurable.
Any MTA is able report the problems it encounters, this is just common decency. They'll typically write to the syslog facility of the host operating system, which can be monitored in any number of ways.
I suppose not all of them implement rate limitation, but a very quick Google search suggests that the three I mentioned are all able to.
I will recommend you Asprin.
Aspirin is an embeddable send-only SMTP server for Java developers.
Take a look at OOP MailScheduler API This library stores the failed emails in database by the Object Serialization. At the scheduled time, the back-ground Thread will select the e-mail from the SQL table and send it to the SMTP server. If the communications with the SMTP server fails, the back-ground Thread will continue to send the e-mail upto the specified count.
精彩评论