use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class BGEmailCompositionStepController method formOK.
@Override
protected void formOK(UserRequest ureq) {
boolean success = false;
try {
File[] attachments = contactForm.getAttachments();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(getIdentity());
bundle.setContactLists(contactForm.getEmailToContactLists());
bundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
MailerResult result = mailService.sendMessage(bundle);
success = result.isSuccessful();
if (contactForm.isTcpFrom()) {
MailBundle ccBundle = new MailBundle();
ccBundle.setContext(context);
ccBundle.setFromId(getIdentity());
ccBundle.setCc(getIdentity());
ccBundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
MailerResult ccResult = mailService.sendMessage(ccBundle);
success = ccResult.isSuccessful();
}
} catch (Exception e) {
logError(null, e);
}
if (success) {
fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class OLATAuthManager method sendConfirmationEmail.
private void sendConfirmationEmail(Identity doer, Identity identity) {
String prefsLanguage = identity.getUser().getPreferences().getLanguage();
Locale locale = I18nManager.getInstance().getLocaleOrDefault(prefsLanguage);
Translator translator = Util.createPackageTranslator(OLATAuthenticationController.class, locale);
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("changepw", 0l));
String changePwUrl = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
String[] args = new String[] { // 0: changed users username
identity.getName(), // 1: changed users email address
UserManager.getInstance().getUserDisplayEmail(identity, locale), // 2: Name (first and last name) of user who changed the password
userManager.getUserDisplayName(doer.getUser()), // 3: configured support email address
WebappHelper.getMailConfig("mailSupport"), // 4: direct link to change password workflow (e.g. https://xx.xx.xx/olat/url/changepw/0)
changePwUrl };
String subject = translator.translate("mail.pwd.subject", args);
String body = translator.translate("mail.pwd.body", args);
MailContext context = new MailContextImpl(null, null, "[Identity:" + identity.getKey() + "]");
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(identity);
bundle.setContent(subject, body);
mailManager.sendMessage(bundle);
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class ReminderServiceImpl method sendReminder.
@Override
public MailerResult sendReminder(Reminder reminder, List<Identity> identitiesToRemind) {
RepositoryEntry entry = reminder.getEntry();
ContactList contactList = new ContactList("Infos");
contactList.addAllIdentites(identitiesToRemind);
MailContext context = new MailContextImpl("[RepositoryEntry:" + entry.getKey() + "]");
Locale locale = I18nModule.getDefaultLocale();
Translator trans = Util.createPackageTranslator(ReminderAdminController.class, locale);
String subject = reminder.getEmailSubject();
String body = reminder.getEmailBody();
if (body.contains("$courseurl")) {
body = body.replace("$courseurl", "<a href=\"$courseurl\">$courseurl</a>");
} else {
body = body + "<p>---<br />" + trans.translate("reminder.from.course", new String[] { "<a href=\"$courseurl\">$coursename</a>" }) + "</p>";
}
String metaId = UUID.randomUUID().toString();
String url = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + entry.getKey();
MailerResult overviewResult = new MailerResult();
ReminderTemplate template = new ReminderTemplate(subject, body, url, entry, locale);
for (Identity identityToRemind : identitiesToRemind) {
String status;
MailBundle bundle = mailManager.makeMailBundle(context, identityToRemind, template, null, metaId, overviewResult);
MailerResult result = mailManager.sendMessage(bundle);
overviewResult.append(result);
List<Identity> failedIdentities = result.getFailedIdentites();
if (failedIdentities != null && failedIdentities.contains(identityToRemind)) {
status = "error";
} else {
status = "ok";
}
reminderDao.markAsSend(reminder, identityToRemind, status);
}
return overviewResult;
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class RepositoryMailing method sendEmail.
public static void sendEmail(Identity ureqIdentity, Identity identity, RepositoryEntry re, Type type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
String emailAlt = identity.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
if (!StringHelper.containsNonWhitespace(email) && !StringHelper.containsNonWhitespace(emailAlt)) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
RepositoryModule repositoryModule = CoreSpringFactory.getImpl(RepositoryModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!repositoryModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
template = getDefaultTemplate(type, re, ureqIdentity);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[RepositoryEntry:" + re.getKey() + "]");
}
String metaId = mailing == null ? null : mailing.getUuid();
MailerResult result = new MailerResult();
MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailManager.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method signAssessmentResult.
@Override
public void signAssessmentResult(AssessmentTestSession candidateSession, DigitalSignatureOptions signatureOptions, Identity assessedIdentity) {
// nothing to do
if (!qtiModule.isDigitalSignatureEnabled() || !signatureOptions.isDigitalSignature())
return;
try {
File resultFile = getAssessmentResultFile(candidateSession);
File signatureFile = new File(resultFile.getParentFile(), "assessmentResultSignature.xml");
File certificateFile = qtiModule.getDigitalSignatureCertificateFile();
X509CertificatePrivateKeyPair kp = CryptoUtil.getX509CertificatePrivateKeyPairPfx(certificateFile, qtiModule.getDigitalSignatureCertificatePassword());
StringBuilder uri = new StringBuilder();
uri.append(Settings.getServerContextPathURI()).append("/").append("RepositoryEntry/").append(candidateSession.getRepositoryEntry().getKey());
if (StringHelper.containsNonWhitespace(candidateSession.getSubIdent())) {
uri.append("/CourseNode/").append(candidateSession.getSubIdent());
}
uri.append("/TestSession/").append(candidateSession.getKey()).append("/assessmentResult.xml");
Document signatureDoc = createSignatureDocumentWrapper(uri.toString(), assessedIdentity, signatureOptions);
XMLDigitalSignatureUtil.signDetached(uri.toString(), resultFile, signatureFile, signatureDoc, certificateFile.getName(), kp.getX509Cert(), kp.getPrivateKey());
if (signatureOptions.isDigitalSignature() && signatureOptions.getMailBundle() != null) {
MailBundle mail = signatureOptions.getMailBundle();
List<File> attachments = new ArrayList<>(2);
attachments.add(signatureFile);
mail.getContent().setAttachments(attachments);
mailManager.sendMessageAsync(mail);
}
} catch (Exception e) {
log.error("", e);
}
}
Aggregations