/** * 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); } }
try { context.setURLFactory(new ExternalServletURLFactory(context)); VelocityContext updatedVelocityContext = prepareVelocityContext(from, to, cc, bcc, vcontext, context); XWiki xwiki = context.getWiki(); XWikiDocument doc = xwiki.getDocument(templateDocFullName, context);
context.setURLFactory(new ExternalServletURLFactory(context)); context.setLocale(LocaleUtils.toLocale(language)); VelocityContext updatedVelocityContext = prepareVelocityContext(from, to, cc, bcc, vcontext, context); XWiki xwiki = context.getWiki(); XWikiDocument doc = xwiki.getDocument(templateDocFullName, context);