/** * Uses an XWiki document to build the message subject and context, based on variables stored in a map. * Sends the email. * * @param templateDocFullName Full name of the template to be used (example: XWiki.MyEmailTemplate). The template * needs to have an XWiki.Email object attached * @param from Email sender * @param to Email recipient * @param cc Email Carbon Copy * @param bcc Email Hidden Carbon Copy * @param language Language of the email * @param parameters variables to be passed to the velocity context * @return True if the email has been sent */ public int sendMailFromTemplate(String templateDocFullName, String from, String to, String cc, String bcc, String language, Map<String, Object> parameters, XWikiContext context) throws XWikiException { VelocityContext vcontext = prepareVelocityContext(from, to, cc, bcc, parameters, context); return sendMailFromTemplate(templateDocFullName, from, to, cc, bcc, language, vcontext, context); } }
@Override public int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language, String documentFullName, VelocityContext vcontext) { try { return getProtectedPlugin().sendMailFromTemplate(documentFullName, from, to, cc, bcc, language, vcontext, this.context); } catch (Exception e) { // If the exception is a null pointer exception there is no message and e.getMessage() is null. if (e.getMessage() != null) { this.context.put("error", e.getMessage()); } LOGGER.error("sendMessageFromTemplate", e); return -1; } }
/** * {@inheritDoc} * * @see MailSender#sendMessageFromTemplate(String, String, String, String, String, String, VelocityContext) */ public int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language, String documentFullName, VelocityContext vcontext) { try { return getProtectedPlugin().sendMailFromTemplate(documentFullName, from, to, cc, bcc, language, vcontext, this.context); } catch (Exception e) { // If the exception is a null pointer exception there is no message and e.getMessage() is null. if (e.getMessage() != null) { this.context.put("error", e.getMessage()); } LOG.error("sendMessageFromTemplate", e); return -1; } }
/** * Uses an XWiki document to build the message subject and context, based on variables stored in a map. Sends the * email. * * @param from Email sender * @param to Email recipient * @param cc Email Carbon Copy * @param bcc Email Hidden Carbon Copy * @param language Language of the email * @param documentFullName Full name of the template to be used (example: XWiki.MyEmailTemplate). The template needs * to have an XWiki.Email object attached * @param parameters variables to be passed to the velocity context * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the * "error" key. */ public int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language, String documentFullName, Map<String, Object> parameters) { try { return getProtectedPlugin().sendMailFromTemplate(documentFullName, from, to, cc, bcc, language, parameters, this.context); } catch (Exception e) { // If the exception is a null pointer exception there is no message and e.getMessage() is null. if (e.getMessage() != null) { this.context.put("error", e.getMessage()); } LOGGER.error("sendMessageFromTemplate", e); return -1; } }
@Override public int sendSuccessMail(Connection connection) { try { Map<String, Object> options = new HashMap<String, Object>(); XWikiContext context = Utils.getContext(); XWiki xwiki = context.getWiki(); MailSenderPlugin mailsender = (MailSenderPlugin) xwiki.getPlugin(MAIL_SENDER, context); String to = getEmail(connection.getInitiatingUser()); options.put("platformName", PLATFORM); options.put(SUBJECT_FIELD_STRING, SUBJECT); options.put(RECIPIENT_NAME, xwiki.getUserName(connection.getInitiatingUser().toString(), null, false, context)); options.put(CONTACTED_USER_NAME, xwiki.getUserName(connection.getContactedUser().toString(), null, false, context)); options.put(MATCH_CASE_ID, connection.getTargetPatient().getDocument().getName()); options.put("matchCaseReferenceId", connection.getReferencePatient().getDocument().getName()); options.put(MATCH_CASE_LINK, xwiki.getDocument(connection.getTargetPatient().getDocument(), context) .getExternalURL(EXTERNAL_LINK_MODE, context)); options.put("matchCaseReferenceLink", xwiki.getDocument(connection.getReferencePatient().getDocument(), context) .getExternalURL(EXTERNAL_LINK_MODE, context)); mailsender.sendMailFromTemplate("PhenoTips.MatchSuccessContact", PHENOMECENTRAL_EMAIL, to, null, null, "", options, context); return 0; } catch (Exception ex) { this.logger.error(FAILED_MAIL_MSG, ex.getMessage(), ex); return 1; } }