Search in sources :

Example 91 with MailBundle

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

the class UserBulkChangeManager method sendLoginDeniedEmail.

public void sendLoginDeniedEmail(Identity identity) {
    String lang = identity.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(lang);
    Translator translator = Util.createPackageTranslator(SystemRolesAndRightsController.class, locale);
    String gender = "";
    UserPropertyHandler handler = userManager.getUserPropertiesConfig().getPropertyHandler(UserConstants.GENDER);
    if (handler instanceof GenderPropertyHandler) {
        String internalGender = ((GenderPropertyHandler) handler).getInternalValue(identity.getUser());
        if (StringHelper.containsNonWhitespace(internalGender)) {
            Translator userPropTrans = userManager.getUserPropertiesConfig().getTranslator(translator);
            gender = userPropTrans.translate("form.name.gender.salutation." + internalGender);
        }
    }
    String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
    email = StringHelper.containsNonWhitespace(email) ? email : "-";
    String[] args = new String[] { // 0: changed users username
    identity.getName(), // 1: changed users email address
    email, // 2: Name (first and last name) of user who changed the password
    userManager.getUserDisplayName(identity.getUser()), // 3: configured support email address
    WebappHelper.getMailConfig("mailSupport"), // 4 last name
    identity.getUser().getProperty(UserConstants.LASTNAME, null), // 5 url system
    getServerURI(), // 6 Mr. Mrs.
    gender };
    MailBundle bundle = new MailBundle();
    bundle.setToId(identity);
    bundle.setContent(translator.translate("mailtemplate.login.denied.subject", args), translator.translate("mailtemplate.login.denied.body", args));
    mailManager.sendExternMessage(bundle, null, false);
}
Also used : Locale(java.util.Locale) Translator(org.olat.core.gui.translator.Translator) GenderPropertyHandler(org.olat.user.propertyhandlers.GenderPropertyHandler) MailBundle(org.olat.core.util.mail.MailBundle) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 92 with MailBundle

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

the class UserImportController method sendMailToNewIdentities.

private void sendMailToNewIdentities(Map<TransientIdentity, Identity> newIdentities) {
    MailerResult result = new MailerResult();
    for (Map.Entry<TransientIdentity, Identity> newEntry : newIdentities.entrySet()) {
        if (newEntry.getKey() != null && newEntry.getValue() != null) {
            Identity newIdentity = newEntry.getValue();
            MailTemplate template = createMailTemplateForNewIdentity(newIdentity, newEntry.getKey());
            MailBundle bundle = mailService.makeMailBundle(null, newIdentity, template, getIdentity(), null, result);
            if (bundle != null) {
                mailService.sendExternMessage(bundle, result, true);
            }
        }
    }
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) Map(java.util.Map) HashMap(java.util.HashMap)

Example 93 with MailBundle

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

the class SendDocumentsByEMailController method sendEmail.

protected void sendEmail(List<Identity> tos, String subject, String body, UserRequest ureq) {
    File[] attachmentArray = null;
    if (attachments != null && !attachments.isEmpty() && allowAttachments) {
        attachmentArray = attachments.toArray(new File[attachments.size()]);
    }
    MailerResult result = new MailerResult();
    String metaId = UUID.randomUUID().toString().replace("-", "");
    for (Identity to : tos) {
        MailBundle bundle = new MailBundle();
        bundle.setToId(to);
        bundle.setMetaId(metaId);
        bundle.setFromId(ureq.getIdentity());
        bundle.setContent(subject, body, attachmentArray);
        result.append(mailManager.sendMessage(bundle));
    }
    MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File)

Example 94 with MailBundle

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

the class GTAParticipantController method doSubmissionEmail.

private void doSubmissionEmail() {
    String body = config.getStringValue(GTACourseNode.GTASK_SUBMISSION_TEXT);
    if (StringHelper.containsNonWhitespace(body)) {
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        List<Identity> recipientsTO;
        File submitDirectory;
        if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
            recipientsTO = businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());
            submitDirectory = gtaManager.getSubmitDirectory(courseEnv, gtaNode, assessedGroup);
        } else {
            recipientsTO = Collections.singletonList(assessedIdentity);
            submitDirectory = gtaManager.getSubmitDirectory(courseEnv, gtaNode, assessedIdentity);
        }
        String subject = translate("submission.mail.subject");
        File[] files = TaskHelper.getDocuments(submitDirectory);
        MailTemplate template = new GTAMailTemplate(subject, body, files, getIdentity(), getTranslator());
        MailerResult result = new MailerResult();
        MailBundle[] bundles = mailManager.makeMailBundles(context, recipientsTO, template, null, UUID.randomUUID().toString(), result);
        mailManager.sendMessage(bundles);
    }
}
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) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File)

Example 95 with MailBundle

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

the class IQEditReplaceWizard method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == mailCtr && event == Event.DONE_EVENT) {
        MailTemplate mailTemplate = mailCtr.getMailTemplate();
        if (mailTemplate != null) {
            MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
            String metaId = UUID.randomUUID().toString().replace("-", "");
            MailerResult result = new MailerResult();
            MailBundle[] bundles = mailManager.makeMailBundles(context, learners, mailTemplate, getIdentity(), metaId, result);
            result.append(mailManager.sendMessage(bundles));
            if (mailTemplate.getCpfrom()) {
                MailBundle ccBundle = mailManager.makeMailBundle(context, getIdentity(), mailTemplate, getIdentity(), metaId, result);
                result.append(mailManager.sendMessage(ccBundle));
            }
        }
        fireEvent(ureq, Event.DONE_EVENT);
    } else if (source == searchCtr && event == ReferencableEntriesSearchController.EVENT_REPOSITORY_ENTRY_SELECTED) {
        selectedRepositoryEntry = searchCtr.getSelectedEntry();
        doStep2(ureq);
    }
}
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