Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should a Java program handle an external mail server being down?

I have a constantly-running Java program that needs to send an email whenever it encounters a problem. However it is possible that the mail server it uses could be down at the time it tries to send the email.

What is the best way to ensure that the email will be delivered when the mail server comes back up?

like image 372
jwaddell Avatar asked Dec 08 '22 05:12

jwaddell


1 Answers

Queue up the requests. Have a separate thread which merely waits for something to enter the queue, then tries to email it. If it fails, it waits a few hours and tries again. Once it sends a message, it goes back to the queue to get the next message.

like image 197
S.Lott Avatar answered Dec 09 '22 18:12

S.Lott