use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class MailManagerTest method testGetOutbox.
@Test
public void testGetOutbox() {
// send a mail
Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-5-" + UUID.randomUUID().toString());
Identity toId = JunitTestHelper.createAndPersistIdentityAsUser("mail-6-" + UUID.randomUUID().toString());
MailBundle bundle = new MailBundle();
bundle.setFromId(fromId);
bundle.setToId(toId);
bundle.setContent("Hello outbox", "Content of outbox");
MailerResult result = mailManager.sendMessage(bundle);
Assert.assertNotNull(result);
Assert.assertEquals(MailerResult.OK, result.getReturnCode());
dbInstance.commitAndCloseSession();
// retrieve the outbox of toId (with lazy loading)
List<DBMailLight> sendedMails = mailManager.getOutbox(fromId, 0, -1, false);
Assert.assertNotNull(sendedMails);
Assert.assertEquals(1, sendedMails.size());
DBMailLight sendedMail = sendedMails.get(0);
Assert.assertNotNull(sendedMail);
Assert.assertEquals("Hello outbox", sendedMail.getSubject());
dbInstance.commitAndCloseSession();
// retrieve the outbox of toId (with fetch)
List<DBMailLight> sendedMailsWithFetch = mailManager.getOutbox(fromId, 0, -1, true);
Assert.assertNotNull(sendedMailsWithFetch);
Assert.assertEquals(1, sendedMailsWithFetch.size());
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class MailManagerTest method testGetInbox.
@Test
public void testGetInbox() {
// send a mail
Identity fromId = JunitTestHelper.createAndPersistIdentityAsRndUser("mail-3");
Identity toId = JunitTestHelper.createAndPersistIdentityAsRndUser("mail-4");
MailBundle bundle = new MailBundle();
bundle.setFromId(fromId);
bundle.setToId(toId);
bundle.setContent("Hello inbox", "Content of inbox");
MailerResult result = mailManager.sendMessage(bundle);
Assert.assertNotNull(result);
Assert.assertEquals(MailerResult.OK, result.getReturnCode());
dbInstance.commitAndCloseSession();
// retrieve the inbox of toId
List<DBMailLight> incomingMails = mailManager.getInbox(toId, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
Assert.assertNotNull(incomingMails);
Assert.assertEquals(1, incomingMails.size());
DBMailLight incomingMail = incomingMails.get(0);
Assert.assertNotNull(incomingMail);
Assert.assertEquals("Hello inbox", incomingMail.getSubject());
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class MailManagerTest method testDeleteUserData_groupedMail.
@Test
public void testDeleteUserData_groupedMail() {
// send a mail 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());
ContactList ccs = new ContactList("unit-test-cc");
ccs.add(toId_1);
ccs.add(toId_2);
ccs.add(toId_3);
ccs.add(fromId);
MailBundle bundle = new MailBundle();
bundle.setFromId(fromId);
bundle.setContactList(ccs);
bundle.setMetaId(metaId);
bundle.setContent("Hello delList", "Content of delList");
MailerResult result = mailManager.sendMessage(bundle);
Assert.assertNotNull(result);
Assert.assertEquals(MailerResult.OK, result.getReturnCode());
dbInstance.commitAndCloseSession();
// delete the 4 users datas
mailBoxExtension.deleteUserData(toId_1, "lalala", null);
mailBoxExtension.deleteUserData(toId_2, "lalala", null);
mailBoxExtension.deleteUserData(toId_3, "lalala", null);
mailBoxExtension.deleteUserData(fromId, "lalala", null);
dbInstance.commitAndCloseSession();
// check inbox / outbox
List<DBMailLight> deletedMails_1 = mailManager.getInbox(toId_1, null, null, null, 0, -1);
Assert.assertNotNull(deletedMails_1);
Assert.assertTrue(deletedMails_1.isEmpty());
List<DBMailLight> deletedMails_2 = mailManager.getInbox(toId_2, null, null, null, 0, -1);
Assert.assertNotNull(deletedMails_2);
Assert.assertTrue(deletedMails_2.isEmpty());
List<DBMailLight> deletedMails_3 = mailManager.getInbox(toId_3, null, null, null, 0, -1);
Assert.assertNotNull(deletedMails_3);
Assert.assertTrue(deletedMails_3.isEmpty());
List<DBMailLight> deletedMails_4 = mailManager.getOutbox(fromId, 0, -1, true);
Assert.assertNotNull(deletedMails_4);
Assert.assertTrue(deletedMails_4.isEmpty());
// check mail by meta id
List<DBMailLight> deletedMails = mailManager.getEmailsByMetaId(metaId);
Assert.assertNotNull(deletedMails);
Assert.assertTrue(deletedMails.isEmpty());
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method sendCertificate.
private MailerResult sendCertificate(Identity to, RepositoryEntry entry, File certificateFile) {
MailBundle bundle = new MailBundle();
bundle.setToId(to);
bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
List<String> bccs = certificatesModule.getCertificatesBccEmails();
if (bccs.size() > 0) {
ContactList bcc = new ContactList();
bccs.forEach(email -> {
bcc.add(email);
});
bundle.setContactList(bcc);
}
String[] args = new String[] { entry.getDisplayname(), userManager.getUserDisplayName(to) };
String userLanguage = to.getUser().getPreferences().getLanguage();
Locale locale = i18nManager.getLocaleOrDefault(userLanguage);
Translator translator = Util.createPackageTranslator(CertificateController.class, locale);
String subject = translator.translate("certification.email.subject", args);
String body = translator.translate("certification.email.body", args);
bundle.setContent(subject, body, certificateFile);
return mailManager.sendMessage(bundle);
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class ProjectBrokerMailerImpl method sendEmail.
// ////////////////
// Private Methods
// ////////////////
private MailerResult sendEmail(Identity enrolledIdentity, Project project, String subject, String body, Locale locale) {
MailTemplate enrolledMailTemplate = createMailTemplate(project, enrolledIdentity, subject, body, locale);
MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(context, enrolledIdentity, enrolledMailTemplate, null, null, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
log.audit("ProjectBroker: sendEmail to identity.name=" + enrolledIdentity.getName() + " , mailerResult.returnCode=" + result.getReturnCode());
return result;
}
Aggregations