use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class RegistrationManager method sendNewUserNotificationMessage.
/**
* Send a notification messaged to the given notification email address about the registratoin of
* the given new identity.
* @param notificationMailAddress Email address who should be notified. MUST NOT BE NULL
* @param newIdentity The newly registered Identity
*/
public void sendNewUserNotificationMessage(String notificationMailAddress, Identity newIdentity) {
Address from;
Address[] to;
try {
// fxdiff: change from/replyto, see FXOLAT-74
from = new InternetAddress(WebappHelper.getMailConfig("mailReplyTo"));
to = new Address[] { new InternetAddress(notificationMailAddress) };
} catch (AddressException e) {
log.error("Could not send registration notification message, bad mail address", e);
return;
}
MailerResult result = new MailerResult();
User user = newIdentity.getUser();
Locale loc = I18nModule.getDefaultLocale();
String[] userParams = new String[] { newIdentity.getName(), user.getProperty(UserConstants.FIRSTNAME, loc), user.getProperty(UserConstants.LASTNAME, loc), UserManager.getInstance().getUserDisplayEmail(user, loc), user.getPreferences().getLanguage(), Settings.getServerDomainName() + WebappHelper.getServletContextPath() };
Translator trans = Util.createPackageTranslator(RegistrationManager.class, loc);
String subject = trans.translate("reg.notiEmail.subject", userParams);
String body = trans.translate("reg.notiEmail.body", userParams);
MimeMessage msg = mailManager.createMimeMessage(from, to, null, null, body, subject, null, result);
mailManager.sendMessage(msg, result);
if (result.getReturnCode() != MailerResult.OK) {
log.error("Could not send registration notification message, MailerResult was ::" + result.getReturnCode(), null);
}
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class RepositoryEntryDetailsController method doLeave.
protected void doLeave() {
if (guestOnly)
return;
MailerResult result = new MailerResult();
MailPackage reMailing = new MailPackage(result, getWindowControl().getBusinessControl().getAsString(), true);
LeavingStatusList status = new LeavingStatusList();
// leave course
repositoryManager.leave(getIdentity(), entry, status, reMailing);
// leave groups
businessGroupService.leave(getIdentity(), entry, status, reMailing);
// make sur all changes are committed
DBFactory.getInstance().commit();
if (status.isWarningManagedGroup() || status.isWarningManagedCourse()) {
showWarning("sign.out.warning.managed");
} else if (status.isWarningGroupWithMultipleResources()) {
showWarning("sign.out.warning.mutiple.resources");
} else {
showInfo("sign.out.success", new String[] { entry.getDisplayname() });
}
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class UnpublishResourceCallback method execute.
@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
MailTemplate mailTemplate = (MailTemplate) runContext.get("mailTemplate");
if (mailTemplate != null) {
List<Identity> ownerList = new ArrayList<Identity>();
// owners
if (repositoryService.hasRole(ureq.getIdentity(), repositoryEntry, GroupRoles.owner.name())) {
ownerList = repositoryService.getMembers(repositoryEntry, GroupRoles.owner.name());
}
String businessPath = wControl.getBusinessControl().getAsString();
MailContext context = new MailContextImpl(businessPath);
String metaId = UUID.randomUUID().toString().replace("-", "");
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, ownerList, mailTemplate, ureq.getIdentity(), metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, ureq.getIdentity(), mailTemplate, ureq.getIdentity(), metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
StringBuilder errorMessage = new StringBuilder();
StringBuilder warningMessage = new StringBuilder();
MailHelper.appendErrorsAndWarnings(result, errorMessage, warningMessage, ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
if (warningMessage.length() > 0) {
wControl.setWarning(warningMessage.toString());
}
if (errorMessage.length() > 0) {
wControl.setError(errorMessage.toString());
}
ownerList.clear();
}
// update status
repositoryEntry = repositoryService.loadByKey(repositoryEntry.getKey());
repositoryEntry.setStatusCode(RepositoryEntryStatus.REPOSITORY_STATUS_CLOSED);
repositoryEntry = DBFactory.getInstance().getCurrentEntityManager().merge(repositoryEntry);
// clean catalog
Object cleanCatalog = runContext.get("cleanCatalog");
if (cleanCatalog != null && Boolean.TRUE.equals(cleanCatalog)) {
CoreSpringFactory.getImpl(CatalogManager.class).resourceableDeleted(repositoryEntry);
}
// clean groups
Object cleanGroups = runContext.get("cleanGroups");
if (cleanGroups != null && Boolean.TRUE.equals(cleanGroups)) {
doCleanGroups(ureq.getIdentity());
}
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_CLOSE, getClass());
log.audit("Repository entry " + repositoryEntry.getDisplayname() + " ( " + repositoryEntry.getOlatResource() + " ) closed");
return StepsMainRunController.DONE_MODIFIED;
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class MailManagerTest method testGetEmailByMetaId.
@Test
public void testGetEmailByMetaId() {
// send a mail
String metaId = UUID.randomUUID().toString();
Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-5-" + UUID.randomUUID().toString());
Identity toId = JunitTestHelper.createAndPersistIdentityAsUser("mail-6-" + UUID.randomUUID().toString());
dbInstance.commitAndCloseSession();
MailBundle bundle = new MailBundle();
bundle.setFromId(fromId);
bundle.setToId(toId);
bundle.setMetaId(metaId);
bundle.setContent("Hello meta ID", "Meta ID");
MailerResult result = mailManager.sendMessage(bundle);
Assert.assertNotNull(result);
Assert.assertEquals(MailerResult.OK, result.getReturnCode());
dbInstance.commitAndCloseSession();
// retrieve the inbox of toId
List<DBMailLight> mails = mailManager.getEmailsByMetaId(metaId);
Assert.assertNotNull(mails);
Assert.assertEquals(1, mails.size());
DBMailLight mail = mails.get(0);
Assert.assertNotNull(mail);
Assert.assertEquals("Hello meta ID", mail.getSubject());
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class MailManagerTest method testDeleteUserData_separatedMail.
@Test
public void testDeleteUserData_separatedMail() {
// send a mail as separated e-mails to three ids
String metaId = UUID.randomUUID().toString();
Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-7-" + UUID.randomUUID().toString());
Identity toId_1 = JunitTestHelper.createAndPersistIdentityAsUser("mail-8-" + UUID.randomUUID().toString());
Identity toId_2 = JunitTestHelper.createAndPersistIdentityAsUser("mail-9-" + UUID.randomUUID().toString());
Identity toId_3 = JunitTestHelper.createAndPersistIdentityAsUser("mail-10-" + UUID.randomUUID().toString());
MailBundle bundle_1 = new MailBundle();
bundle_1.setFromId(fromId);
bundle_1.setToId(toId_1);
bundle_1.setMetaId(metaId);
bundle_1.setContent("Hello ccList", "Content of ccList");
MailerResult result1 = mailManager.sendMessage(bundle_1);
Assert.assertNotNull(result1);
Assert.assertEquals(MailerResult.OK, result1.getReturnCode());
MailBundle bundle_2 = new MailBundle();
bundle_2.setFromId(fromId);
bundle_2.setToId(toId_2);
bundle_2.setMetaId(metaId);
bundle_2.setContent("Hello ccList", "Content of ccList");
MailerResult result2 = mailManager.sendMessage(bundle_2);
Assert.assertNotNull(result2);
Assert.assertEquals(MailerResult.OK, result2.getReturnCode());
MailBundle bundle_3 = new MailBundle();
bundle_3.setFromId(fromId);
bundle_3.setToId(toId_3);
bundle_3.setMetaId(metaId);
bundle_3.setContent("Hello ccList", "Content of ccList");
MailerResult result3 = mailManager.sendMessage(bundle_3);
Assert.assertNotNull(result3);
Assert.assertEquals(MailerResult.OK, result3.getReturnCode());
dbInstance.commitAndCloseSession();
// delete the 4 users datas
mailBoxExtension.deleteUserData(fromId, "lalala", null);
mailBoxExtension.deleteUserData(toId_1, "lalala", null);
mailBoxExtension.deleteUserData(toId_2, "lalala", null);
mailBoxExtension.deleteUserData(toId_3, "lalala", null);
dbInstance.commitAndCloseSession();
// check mail by meta id
List<DBMailLight> deletedMails = mailManager.getEmailsByMetaId(metaId);
Assert.assertNotNull(deletedMails);
Assert.assertTrue(deletedMails.isEmpty());
}
Aggregations