Search in sources :

Example 86 with MailTemplate

use of org.olat.core.util.mail.MailTemplate 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

MailTemplate (org.olat.core.util.mail.MailTemplate)86 Identity (org.olat.core.id.Identity)62 MailerResult (org.olat.core.util.mail.MailerResult)46 MailBundle (org.olat.core.util.mail.MailBundle)32 MailContext (org.olat.core.util.mail.MailContext)30 MailContextImpl (org.olat.core.util.mail.MailContextImpl)30 VelocityContext (org.apache.velocity.VelocityContext)28 ArrayList (java.util.ArrayList)20 List (java.util.List)16 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)14 MailNotificationEditController (org.olat.core.util.mail.MailNotificationEditController)14 User (org.olat.core.id.User)12 Test (org.junit.Test)10 UserRequest (org.olat.core.gui.UserRequest)10 WindowControl (org.olat.core.gui.control.WindowControl)10 MailPackage (org.olat.core.util.mail.MailPackage)8 Property (org.olat.properties.Property)7 File (java.io.File)6 Locale (java.util.Locale)6 TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)6