Search in sources :

Example 81 with MailBundle

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());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 82 with MailBundle

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());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 83 with MailBundle

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());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 84 with MailBundle

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);
}
Also used : Locale(java.util.Locale) Translator(org.olat.core.gui.translator.Translator) ContactList(org.olat.core.util.mail.ContactList) MailBundle(org.olat.core.util.mail.MailBundle)

Example 85 with MailBundle

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;
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) MailBundle(org.olat.core.util.mail.MailBundle)

Aggregations

MailBundle (org.olat.core.util.mail.MailBundle)126 MailerResult (org.olat.core.util.mail.MailerResult)100 Identity (org.olat.core.id.Identity)72 MailContextImpl (org.olat.core.util.mail.MailContextImpl)72 MailContext (org.olat.core.util.mail.MailContext)70 MailTemplate (org.olat.core.util.mail.MailTemplate)32 Translator (org.olat.core.gui.translator.Translator)28 ContactList (org.olat.core.util.mail.ContactList)28 Locale (java.util.Locale)20 File (java.io.File)18 Date (java.util.Date)16 Test (org.junit.Test)14 MailManager (org.olat.core.util.mail.MailManager)14 DBMailLight (org.olat.core.util.mail.model.DBMailLight)12 ArrayList (java.util.ArrayList)10 Property (org.olat.properties.Property)7 ContextEntry (org.olat.core.id.context.ContextEntry)6 AssertException (org.olat.core.logging.AssertException)6 TemporaryKey (org.olat.registration.TemporaryKey)6 UserManager (org.olat.user.UserManager)6