Sending 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 provide mentioned features).
Create a new session object by calling getDefaultInstance() method and passing properties as argument to get all of the important properties like hostname of the SMTP server etc. Create a MimeMessage object by passing the session object created in previous step. The final step is to send email using the javax. mail.
SMTP is an acronym for Simple Mail Transfer Protocol. It is an Internet standard for electronic mail (e-mail) transmission across Internet Protocol (IP) networks.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With