Index: impl/InvitationManagerImpl.java =================================================================== --- impl/InvitationManagerImpl.java (revision 9750) +++ impl/InvitationManagerImpl.java (working copy) @@ -1464,22 +1464,25 @@ String strToUsers = join(toUsers, ","); MailSenderPlugin mailSender = getMailSenderPlugin(context); + + //gets the demplae coc XWikiDocument mailDoc = context.getWiki().getDocument(templateDocFullName, context); XWikiDocument translatedMailDoc = mailDoc.getTranslatedDocument(context); - mailSender.prepareVelocityContext(fromUser, strToUsers, "", "", vContext, context); - vContext.put("xwiki", new XWiki(context.getWiki(), context)); + + //puts some generic variables in the velocity rendering context so we can write the template doc almost as a normal document + vContext.put("xwiki", new XWiki(context.getWiki(), context)); vContext.put("context", new com.xpn.xwiki.api.Context(context)); - String mailSubject = - XWikiVelocityRenderer.evaluate(translatedMailDoc.getTitle(), templateDocFullName, - vContext, context); - String mailContent = - XWikiVelocityRenderer.evaluate(translatedMailDoc.getContent(), templateDocFullName, - vContext, context); + vContext.put("doc", translatedMailDoc); + + //rendering the template document with the defined velocity context. the subject of the mail is the subject of the template doc and the content of the mail is the content of the doc + String mailSubject = XWikiVelocityRenderer.evaluate(translatedMailDoc.getTitle(), templateDocFullName, vContext, context); + String mailContent = XWikiVelocityRenderer.evaluate(translatedMailDoc.getContent(), templateDocFullName, vContext, context); + //creates a new mail Mail mail = new Mail(fromUser, strToUsers, null, null, mailSubject, mailContent, null); try { - mailSender.sendMail(mail, context); + mailSender.sendMail(mail,context); } catch (Exception e) { throw new InvitationManagerException(InvitationManagerException.MODULE_PLUGIN_INVITATIONMANAGER, InvitationManagerException.ERROR_INVITATION_SENDING_EMAIL_FAILED,