class AcmEmailContentGeneratorService {

    public String generateEmailBody(EmailWithEmbeddedLinksDTO emailDTO, String emailAddress, Authentication authentication)
    {
        emailDTO.setTemplatingEngine(getTemplatingEngine());

        StringBuilder body = new StringBuilder();
        body.append(emailDTO.getBody() != null ? emailDTO.getBody() : "").append("<br/>");

        if (emailDTO.getFileIds() != null)
        {
            for (Long fileId : emailDTO.getFileIds())
            {
                EcmFile ecmFile = getEcmFileDao().find(fileId);
                String token = authenticationTokenService.generateAndSaveAuthenticationToken(fileId, emailAddress, authentication);
                body.append(fileId).append("&version=").append(ecmFile.getActiveVersionTag()).append("&acm_email_ticket=").append(token).append("<br/>");
                emailDTO.getTokens().add(token);
                emailDTO.setFileVersion(ecmFile.getActiveVersionTag());
            }
        }

        return emailDTO.buildMessageBodyFromTemplate(body.toString());
    }

}