class AcknowledgementDocumentService {

    public void emailAcknowledgement(Long requestId)
    {
        if (!foiaConfigurationService.readConfiguration().getReceivedDateEnabled())
        {
            FOIARequest request = getRequestDao().find(requestId);
            String emailAddress = extractRequestorEmailAddress(request.getOriginator().getPerson());
            if (emailAddress != null)
            {
                EmailWithAttachmentsDTO emailData = new EmailWithAttachmentsDTO();
                emailData.setEmailAddresses(Arrays.asList(emailAddress));

                emailData.setSubject(String.format("%s %s", request.getRequestType(), request.getCaseNumber()));
                emailData.setHeader(EMAIL_HEADER_ATTACHMENT);
                try
                {
                    String body = getTemplatingEngine().process(emailBodyTemplate, "request", request);
                    emailData.setBody(body);
                    emailData.setTemplate(body);
                }
                catch (TemplateException | IOException e)
                {
                    // failing to send an email should not break the flow
                    log.error("Unable to generate email for {} about {} with ID [{}]", emailAddress, request.getObjectType(), requestId, e);
                    emailData.setBody(EMAIL_BODY_ATTACHMENT);
                }
                emailData.setFooter(EMAIL_FOOTER_ATTACHMENT);

                FOIADocumentDescriptor documentDescriptor = documentGeneratorService.getDocumentDescriptor(request, FOIAConstants.ACK);

                EcmFile ackFile = getEcmFileDao().findForContainerAttachmentFolderAndFileType(request.getContainer().getId(),
                        request.getContainer().getAttachmentFolder().getId(), documentDescriptor.getDoctype());
                emailData.setAttachmentIds(Arrays.asList(ackFile.getFileId()));
                Authentication auth = SecurityContextHolder.getContext().getAuthentication();

                String userIdOrName = request.getCreator();
                try
                {
                    if (request.isExternal()) // request from external portal
                    {
                        getNotificationSender().sendEmailWithAttachments(emailData, auth, userIdOrName);
                    }
                    else // request from foia app
                    {
                        getNotificationSender().sendEmailWithAttachments(emailData, auth, getUserDao().findByUserId(userIdOrName));
                    }

                }
                catch (Exception e)
                {
                    log.error("Unable to email {} for {} [{}]", request.getRequestType(), documentDescriptor.getDoctype(), requestId, e);
                }
            }
        }
    }

}