class SmtpService implements AcmEmailSenderService, ApplicationEventPublisherAware {

    @Override
    public List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication,
            AcmUser user)
    {
        List<EmailWithEmbeddedLinksResultDTO> emailResultList = new ArrayList<>();
        Exception exception = null;

        Long parentId = setFilenames(in);

        for (String emailAddress : in.getEmailAddresses())
        {
            try
            {
                acmMailSender.sendEmail(emailAddress, in.getSubject(), makeNote(emailAddress, in, authentication));
            }
            catch (Exception e)
            {
                exception = e;
            }

            if (exception != null)
            {
                emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, false));
                log.error("Email message not sent ...", exception);
            }
            else
            {
                emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, true));
            }

            SmtpSentEventHyperlink event = new SmtpSentEventHyperlink(in, user.getUserId(), parentId, in.getParentType());

            boolean success = (exception == null);
            event.setSucceeded(success);
            eventPublisher.publishEvent(event);
        }
        return emailResultList;
    }

}