class SmtpService implements AcmEmailSenderService, ApplicationEventPublisherAware {

    @Override
    public void sendEmailWithAttachments(EmailWithAttachmentsDTO in, Authentication authentication, AcmUser user)
            throws Exception
    {
        in.setTemplatingEngine(getTemplatingEngine());

        Exception exception = null;

        List<SmtpEventSentEvent> sentEvents = new ArrayList<>();
        Map<String, InputStreamDataSource> attachments = processAttachments(in, user, sentEvents);

        for (String emailAddress : in.getEmailAddresses())
        {
            try
            {
                acmMailSender.sendMultipartEmail(emailAddress, in.getSubject(), in.getMessageBody(),
                        new ArrayList<>(attachments.values()));
            }
            catch (Exception e)
            {
                exception = e;
                log.error("Failed to send email to [{}].", emailAddress, exception);
            }
        }
        for (SmtpEventSentEvent event : sentEvents)
        {
            boolean success = (exception == null);
            event.setSucceeded(success);
            eventPublisher.publishEvent(event);
        }
    }

}