protected String getContent() throws OperationException, IOException { message = message.trim(); if (message.startsWith("template:")) { String name = message.substring("template:".length()).trim(); URL url = MailTemplateHelper.getTemplate(name); if (url == null) { throw new OperationException("No such mail template: " + name); } InputStream in = url.openStream(); return FileUtils.read(in); } else { return StringEscapeUtils.unescapeHtml(message); } }
protected void send(DocumentModel doc) throws TemplateException, RenderingException, OperationException, MessagingException, IOException { // TODO should sent one by one to each recipient? and have the template // rendered for each recipient? Use: "mailto" var name? try { Map<String, Object> map = Scripting.initBindings(ctx); // do not use document wrapper which is working only in mvel. map.put("Document", doc); map.put("docUrl", MailTemplateHelper.getDocumentUrl(doc, viewId)); map.put("subject", subject); map.put("to", to); map.put("toResolved", MailBox.fetchPersonsFromList(to, isStrict)); map.put("from", from); map.put("fromResolved", MailBox.fetchPersonsFromString(from, isStrict)); map.put("from", cc); map.put("fromResolved", MailBox.fetchPersonsFromList(cc, isStrict)); map.put("from", bcc); map.put("fromResolved", MailBox.fetchPersonsFromList(bcc, isStrict)); map.put("from", replyto); map.put("fromResolved", MailBox.fetchPersonsFromList(replyto, isStrict)); map.put("viewId", viewId); map.put("baseUrl", NotificationServiceHelper.getNotificationService().getServerUrlPrefix()); map.put("Runtime", Framework.getRuntime()); Mailer.Message msg = createMessage(doc, getContent(), map); msg.setSubject(subject, "UTF-8"); addMailBoxInfo(msg); msg.send(); } catch (ClientException | TemplateException | RenderingException | OperationException | MessagingException | IOException e) { if (rollbackOnError) { throw e; } else { log.warn( String.format( "An error occured while trying to execute the %s operation, see complete stack trace below. Continuing chain since 'rollbackOnError' was set to false.", ID), e); } } }