I didn't look at the code, but one approach would be to run the mail sending in a loop until there are no exceptions, putting the current thread to sleep each time there is an exception - may be for 30 seconds or so. This assumes that the mail sending is done in a thread that's separate from the main execution thread, but that's good practice anyway for network operations for which you don't need (or won't get) an immediate answer.
There is no way you can provide reliable, immediate feedback for sending email. The host might be down, in which case the email sending is delayed by 4 hours or more. That's how SMTP works, no way around that.
Then use a proper mail server for sending. That way you'll get notifications emails if the mail is delayed, and bounces if it doesn't go through at all. Retrying to send email in a short time frame is unlikely to yield better results than letting SMTP and the mail server handle all that for you.
Yeah.. I don't get this exception in all servers.(They must be properly handling the requests.)
In a particular server, i get this exception while doing continuous testing. (421 response comes when the server is busy)
My concern is only for this particular server. I just need to retry few times.
After searching through internet never found a proper solution, just doing for loop, in Exception block catching exception stack, if no exception null
if not null, again next iteration in for loop
each iteration if not null, add it to List<String> for audit
and make this whole thing async if possible as one round may take around 7/8 seconds
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad: