Search in sources :

Example 26 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.

the class DENManager method getAddedMailTemplate.

/**
 * Generates a mail template for users who were added to a date
 * @param identity
 * @param event
 * @param translator
 * @return MailTemplate
 */
protected MailTemplate getAddedMailTemplate(UserRequest ureq, String subjectStr, Translator translator) {
    Identity identity = ureq.getIdentity();
    String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
    String subject = translator.translate("mail.participants.add.subject", bodyArgs);
    String body = translator.translate("mail.participants.add.body", bodyArgs);
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity ident) {
        // 
        }
    };
    return mailTempl;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 27 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.

the class DENManager method getRemovedMailTemplate.

/**
 * Generates a mail template for users who were removed from a date
 * @param identity
 * @param event
 * @param trans
 * @return MailTemplate
 */
protected MailTemplate getRemovedMailTemplate(UserRequest ureq, String subjectStr, Translator trans) {
    Identity identity = ureq.getIdentity();
    String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
    String subject = trans.translate("mail.participants.remove.subject", bodyArgs);
    String body = trans.translate("mail.participants.remove.body", bodyArgs);
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity ident) {
        // 
        }
    };
    return mailTempl;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 28 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.

the class SelectionForm method handleEmailButtonEvent.

private void handleEmailButtonEvent(UserRequest ureq, TableMultiSelectEvent tmse) {
    List<Identity> identities = tdm.getObjects(tmse.getSelection());
    if (identities.size() > 0) {
        selectedIdentities = identities;
        MailTemplate deleteMailTemplate = createMailTemplate(translate(KEY_EMAIL_SUBJECT), translate(KEY_EMAIL_BODY));
        deleteMailTemplate.setCpfrom(Boolean.FALSE);
        deleteMailTemplate.addToContext("lastloginduration", Integer.toString(UserDeletionManager.getInstance().getLastLoginDuration()));
        deleteMailTemplate.addToContext("durationdeleteemail", Integer.toString(UserDeletionManager.getInstance().getDeleteEmailDuration()));
        removeAsListenerAndDispose(deleteUserMailCtr);
        deleteUserMailCtr = new MailNotificationEditController(getWindowControl(), ureq, deleteMailTemplate, true, false, false);
        listenTo(deleteUserMailCtr);
        removeAsListenerAndDispose(cmc);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), deleteUserMailCtr.getInitialComponent());
        listenTo(cmc);
        cmc.activate();
    } else {
        showWarning("nothing.selected.msg");
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) MailNotificationEditController(org.olat.core.util.mail.MailNotificationEditController)

Example 29 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.

the class UserImportController method createMailTemplateForNewIdentity.

private MailTemplate createMailTemplateForNewIdentity(Identity identity, TransientIdentity transientIdentity) {
    // get some data about the actor and fetch the translated subject / body via i18n module
    String[] bodyArgs = new String[] { // {0}
    identity.getName(), // {1}
    identity.getUser().getProperty(UserConstants.FIRSTNAME, null), // {2}
    identity.getUser().getProperty(UserConstants.LASTNAME, null), // {3}
    UserManager.getInstance().getUserDisplayEmail(identity, getLocale()), // {4}
    Settings.getServerContextPathURI(), // {5}
    transientIdentity.getPassword() };
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
    Translator translator = Util.createPackageTranslator(UserImportController.class, locale);
    String subject = translator.translate("mail.new.identity.subject");
    String body = translator.translate("mail.new.identity.text", bodyArgs);
    // create a mail template which all these data
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity identity) {
            // Put user variables into velocity context
            User user = identity.getUser();
            context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
            context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
            // the email of the user, needs to stay named 'login'
            context.put("login", user.getProperty(UserConstants.EMAIL, null));
        }
    };
    return mailTempl;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) Translator(org.olat.core.gui.translator.Translator) VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 30 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.

the class WaitingGroupController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Controller sourceController, Event event) {
    if (sourceController == tableCtr) {
        if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            // Multiselect events
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(COMMAND_MOVE_USER_WAITINGLIST)) {
                if (tmse.getSelection().isEmpty()) {
                    getWindowControl().setWarning(translate("msg.selectionempty"));
                } else {
                    List<Identity> objects = identitiesTableModel.getIdentities(tmse.getSelection());
                    toTransfer = objects;
                    removeAsListenerAndDispose(transferMailCtr);
                    transferMailCtr = new MailNotificationEditController(getWindowControl(), ureq, transferUserMailTempl, true, mandatoryEmail, true);
                    listenTo(transferMailCtr);
                    removeAsListenerAndDispose(cmc);
                    cmc = new CloseableModalController(getWindowControl(), translate("close"), transferMailCtr.getInitialComponent());
                    listenTo(cmc);
                    cmc.activate();
                    // don't execute super method
                    return;
                }
            }
        }
    } else if (sourceController == transferMailCtr) {
        if (event == Event.DONE_EVENT) {
            // fetch configured mail template and finish this controller workflow
            MailTemplate customTransferTemplate = transferMailCtr.getMailTemplate();
            cmc.deactivate();
            IdentitiesMoveEvent identitiesMoveEvent = new IdentitiesMoveEvent(toTransfer);
            identitiesMoveEvent.setMailTemplate(customTransferTemplate);
            fireEvent(ureq, identitiesMoveEvent);
            StringBuilder infoMessage = new StringBuilder();
            for (Identity identity : identitiesMoveEvent.getNotMovedIdentities()) {
                String fullName = userManager.getUserDisplayName(identity);
                infoMessage.append(translate("msg.alreadyinwaiitinggroup", fullName)).append("<br />");
            }
            // report any errors on screen
            if (infoMessage.length() > 0)
                getWindowControl().setInfo(infoMessage.toString());
            // don't execute super method
            return;
        } else if (event == Event.CANCELLED_EVENT) {
            cmc.deactivate();
            // don't execute super method
            return;
        } else {
            throw new RuntimeException("unknown event ::" + event.getCommand());
        }
    }
    // it is no WaitingGroupController event, forward it to super class GroupController
    super.event(ureq, sourceController, event);
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) MailNotificationEditController(org.olat.core.util.mail.MailNotificationEditController)

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