use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class DENManager method getRemovedMailTemplate.
/**
* Generates a mail template for users who were removed from a date
* @param identity
* @param event
* @param trans
* @return MailTemplate
*/
protected MailTemplate getRemovedMailTemplate(UserRequest ureq, String subjectStr, Translator trans) {
Identity identity = ureq.getIdentity();
String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
String subject = trans.translate("mail.participants.remove.subject", bodyArgs);
String body = trans.translate("mail.participants.remove.body", bodyArgs);
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity ident) {
//
}
};
return mailTempl;
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class DENManager method getAddedMailTemplate.
/**
* Generates a mail template for users who were added to a date
* @param identity
* @param event
* @param translator
* @return MailTemplate
*/
protected MailTemplate getAddedMailTemplate(UserRequest ureq, String subjectStr, Translator translator) {
Identity identity = ureq.getIdentity();
String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
String subject = translator.translate("mail.participants.add.subject", bodyArgs);
String body = translator.translate("mail.participants.add.body", bodyArgs);
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity ident) {
//
}
};
return mailTempl;
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class RepositoryMailing method createMailTemplate.
private static MailTemplate createMailTemplate(RepositoryEntry re, Identity actor, String subjectKey, String bodyKey) {
// build learning resources as list of url as string
final String reName = re.getDisplayname();
final String redescription = (StringHelper.containsNonWhitespace(re.getDescription()) ? FilterFactory.getHtmlTagAndDescapingFilter().filter(re.getDescription()) : "");
final String reUrl = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + re.getKey();
// get some data about the actor and fetch the translated subject / body via i18n module
Locale locale = I18nManager.getInstance().getLocaleOrDefault(actor.getUser().getPreferences().getLanguage());
String[] bodyArgs = new String[] { actor.getUser().getProperty(UserConstants.FIRSTNAME, null), actor.getUser().getProperty(UserConstants.LASTNAME, null), UserManager.getInstance().getUserDisplayEmail(actor, locale), // 2x for compatibility with old i18m properties
UserManager.getInstance().getUserDisplayEmail(actor, locale) };
Translator trans = Util.createPackageTranslator(RepositoryManager.class, locale);
String subject = trans.translate(subjectKey);
String body = trans.translate(bodyKey, bodyArgs);
// create a mail template which all these data
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// Put user variables into velocity context
User user = identity.getUser();
context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
context.put("login", UserManager.getInstance().getUserDisplayEmail(user, locale));
// Put variables from greater context
context.put("coursename", reName);
context.put("coursedescription", redescription);
context.put("courseurl", reUrl);
}
};
return mailTempl;
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class MailTest method testMailAttachmentsInvalid.
/**
* Test for the mail template and the context variable methods
*/
@Test
public void testMailAttachmentsInvalid() {
String subject = "Subject: Hello $firstname with attachment";
String body = "Body: \n\n Hey $login, here's a file for you: ";
// some attachemnts - but no file
File[] attachments = new File[1];
MailTemplate template = new MailTemplate(subject, body, attachments) {
@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("login", identity.getName());
}
};
// some recipients data
List<Identity> recipients = new ArrayList<Identity>();
recipients.add(id1);
MailerResult result = new MailerResult();
result = sendMailAsSeparateMails(null, recipients, null, template, id2, null);
assertEquals(MailerResult.ATTACHMENT_INVALID, result.getReturnCode());
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class MailTest method testMailToCcBccForEach.
/**
* Test for the mail template and the context variable methods
*/
@Test
public void testMailToCcBccForEach() {
String subject = "For Each Subject: Hello $firstname $lastname";
String body = "For Each Body: \n\n You ($login) should go to \n\n'$coursename' @ $courseURL$login";
final String coursename = "my course";
final String courseURL = "http://www.mytrashmail.com/myTrashMail_inbox.aspx?email=";
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);
}
};
// some recipients data
List<Identity> recipients = new ArrayList<Identity>();
recipients.add(id1);
recipients.add(id2);
recipients.add(id3);
Identity recipientCC = id4;
// tests with / witthout CC and BCC
MailerResult result = new MailerResult();
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, recipientCC, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
}
Aggregations