Currently our code for sending email messages looks like this:
@Override
public SendEmailResponse sendEmail(DtoEmailMessage dtoEmailMessage) {
try {
MimeMessage mimeMessage = mimeMessageCreator.createMessage(dtoEmailMessage);
javaMailSender.send(mimeMessage);
return SendEmailResponse.ok(channelEmailMessage.getEmailNotification().getTo(), mimeMessage.getMessageID());
} catch (UnsupportedEncodingException | MessagingException | RuntimeException e) {
...
}
}
What has to be improved ?
I want to support a list of reserved smtp servers. So in case if server_1 is failed for 2 or 3 times I wan to try with server_2. In case if server_2 is failed - server_3 is used etc.
I know about spring-retry and spring-hystrix but looks like they are not applicable for current task.
Is there any production ready solution for my task or it is better implement it on my own?
It would better to handle multiple SMTP hosts managed by a load balancer however you can manage in your application code as well.