// Look up the user.
User user = UserBean.getUser(username);
if( user == null ) return;
// Create a message:
PlanetsMailMessage message = new PlanetsMailMessage();
// Add the recipient in properly.
message.addRecipient(user.getFullName() + "<" + user.getEmail() + ">");
// Determine the Testbed URL:
// FIXME This is a HACK for the TB Service URL in emails:
String testbedURL = "http://testbed.planets-project.eu/testbed/";
// String testbedURL = "http://"+AdminManagerImpl.getAuthority()+"/testbed/";
Map<String,Object> model = new HashMap<String,Object>();
model.put("user", user);
model.put("exp", exp);
model.put("expName", exp.getExperimentSetup().getBasicProperties().getExperimentName());
model.put("applicationURL", testbedURL);
VelocityContext velocityContext;
StringWriter result = new StringWriter();
try {
velocityContext = new VelocityContext(model);
velocityEngine.mergeTemplate("eu/planets_project/tb/"+templateName+".vm", velocityContext, result);
} catch (VelocityException ex) {
log.error("Mailing failed! :: "+ex);
return;
} catch (RuntimeException ex) {
log.error("Mailing failed! :: "+ex);
return;
} catch (Exception ex) {
log.error("Mailing failed! :: "+ex);
return;
}
message.setSubject(velocityContext.get("subject").toString());
message.setBody(result.toString());
try {
message.send();
} catch( Exception e ) {
log.error("An error occured while trying to send an email to "+user.getFullName()+"! :: "+e);
e.printStackTrace();
}
}