class MailSenderAdapter {

    @Scheduled(fixedDelay = 10000L)
    @Transactional
    public void sendPendingMessages() {
        messageRepository.findAll().forEach(templateMessage -> {
            try {
                if(templateMessage.isStillRelevant(LocalDateTime.now(clock))) {
                    sendMessage(templateMessage);
                }

                // delete the message when it was sent
                // successfully or is not relevant anymore
                messageRepository.delete(templateMessage);
            } catch (Exception err) {
                log.error("Error sending mail!", err);
            }
        });
    }

    public  MailSenderAdapter(MessageRepository messageRepository,
                             JavaMailSender mailSender,
                             UserService userService,
                             MailConfigurationProperties properties,
                             Clock clock);

}