MailTemplate template = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// Put user variables
User user = identity.getUser();
context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
context.put("login", identity.getName());
// Put variables from greater context, eg. course id, group name etc.
context.put("coursename", coursename);
context.put("courseURL", courseURL);