Search in sources :

Example 71 with MailContextImpl

use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.

the class TaskFolderCallback method sendNotificationEmail.

private void sendNotificationEmail(UserRequest ureq, MailTemplate mailTemplate, List<Identity> recipients) {
    // send the notification mail
    if (mailTemplate != null) {
        Identity sender = ureq.getIdentity();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailerResult result = new MailerResult();
        String metaId = UUID.randomUUID().toString().replace("-", "");
        MailBundle[] bundles = mailManager.makeMailBundles(context, recipients, mailTemplate, sender, metaId, result);
        result.append(mailManager.sendMessage(bundles));
        if (mailTemplate.getCpfrom()) {
            MailBundle ccBundle = mailManager.makeMailBundle(context, sender, mailTemplate, sender, metaId, result);
            result.append(mailManager.sendMessage(ccBundle));
        }
        MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 72 with MailContextImpl

use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.

the class FinishCallback method sendMail.

private boolean sendMail(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
    boolean success = false;
    try {
        ContactList contacts = new ContactList("Forum");
        ListWrapper recipients = (ListWrapper) runContext.get(SendMailStepForm.RECIPIENTS);
        contacts.addAllIdentites(recipients.getListOfIdentity());
        MailContext context = new MailContextImpl(wControl.getBusinessControl().getAsString());
        MailBundle bundle = new MailBundle();
        bundle.setContext(context);
        Identity sender = (Identity) runContext.get(SendMailStepForm.SENDER);
        bundle.setFromId(sender != null ? sender : ureq.getIdentity());
        bundle.setContactLists(new ArrayList<ContactList>(Arrays.asList(contacts)));
        MailTemplate mailTemplate = (MailTemplate) runContext.get(SendMailStepForm.MAIL_TEMPLATE);
        bundle.setContent(mailTemplate.getSubjectTemplate(), mailTemplate.getBodyTemplate());
        MailerResult result = mailService.sendMessage(bundle);
        return success = result.isSuccessful();
    } catch (Exception e) {
        log.error(null, e);
        return success;
    }
}
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) ContactList(org.olat.core.util.mail.ContactList) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity)

Aggregations

MailBundle (org.olat.core.util.mail.MailBundle)72 MailContextImpl (org.olat.core.util.mail.MailContextImpl)72 MailContext (org.olat.core.util.mail.MailContext)70 MailerResult (org.olat.core.util.mail.MailerResult)66 Identity (org.olat.core.id.Identity)44 MailTemplate (org.olat.core.util.mail.MailTemplate)30 ContactList (org.olat.core.util.mail.ContactList)20 File (java.io.File)14 ArrayList (java.util.ArrayList)8 Locale (java.util.Locale)8 MailManager (org.olat.core.util.mail.MailManager)8 Translator (org.olat.core.gui.translator.Translator)7 Property (org.olat.properties.Property)7 ContextEntry (org.olat.core.id.context.ContextEntry)6 HashSet (java.util.HashSet)4 List (java.util.List)4 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)4 IdentitiesRemoveEvent (org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 AssertException (org.olat.core.logging.AssertException)4