Search in sources :

Example 61 with MailBundle

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

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)

Example 62 with MailBundle

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

the class QTI21AssessmentRunController method decorateCourseConfirmation.

public static void decorateCourseConfirmation(AssessmentTestSession candidateSession, DigitalSignatureOptions options, CourseEnvironment courseEnv, CourseNode courseNode, RepositoryEntry testEntry, Date timestamp, Locale locale) {
    MailBundle bundle = new MailBundle();
    bundle.setToId(candidateSession.getIdentity());
    Identity assessedIdentity = candidateSession.getIdentity();
    String fullname = CoreSpringFactory.getImpl(UserManager.class).getUserDisplayName(assessedIdentity);
    Date assessedDate = candidateSession.getFinishTime() == null ? timestamp : candidateSession.getFinishTime();
    String[] args = new String[] { // {0}
    courseEnv.getCourseTitle(), // {1}
    courseEnv.getCourseResourceableId().toString(), // {2}
    courseNode.getShortTitle(), // {3}
    courseNode.getIdent(), // {4}
    testEntry.getDisplayname(), // {5}
    fullname, Formatter.getInstance(locale).formatDateAndTime(// {6}
    assessedDate), // {7}
    assessedIdentity.getName(), assessedIdentity.getUser().getProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, // {8}
    locale), assessedIdentity.getUser().getProperty(UserConstants.INSTITUTIONALNAME, // {9}
    locale) };
    Translator translator = Util.createPackageTranslator(QTI21AssessmentRunController.class, locale);
    String subject = translator.translate("digital.signature.mail.subject", args);
    String body = translator.translate("digital.signature.mail.body", args);
    bundle.setContent(subject, body);
    options.setMailBundle(bundle);
    options.setSubIdentName(courseNode.getShortTitle());
}
Also used : Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 63 with MailBundle

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

the class BGEmailCompositionStepController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    boolean success = false;
    try {
        File[] attachments = contactForm.getAttachments();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailBundle bundle = new MailBundle();
        bundle.setContext(context);
        bundle.setFromId(getIdentity());
        bundle.setContactLists(contactForm.getEmailToContactLists());
        bundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
        MailerResult result = mailService.sendMessage(bundle);
        success = result.isSuccessful();
        if (contactForm.isTcpFrom()) {
            MailBundle ccBundle = new MailBundle();
            ccBundle.setContext(context);
            ccBundle.setFromId(getIdentity());
            ccBundle.setCc(getIdentity());
            ccBundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
            MailerResult ccResult = mailService.sendMessage(ccBundle);
            success = ccResult.isSuccessful();
        }
    } catch (Exception e) {
        logError(null, e);
    }
    if (success) {
        fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File)

Example 64 with MailBundle

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

the class OLATAuthManager method sendConfirmationEmail.

private void sendConfirmationEmail(Identity doer, Identity identity) {
    String prefsLanguage = identity.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(prefsLanguage);
    Translator translator = Util.createPackageTranslator(OLATAuthenticationController.class, locale);
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("changepw", 0l));
    String changePwUrl = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
    String[] args = new String[] { // 0: changed users username
    identity.getName(), // 1: changed users email address
    UserManager.getInstance().getUserDisplayEmail(identity, locale), // 2: Name (first and last name) of user who changed the password
    userManager.getUserDisplayName(doer.getUser()), // 3: configured support email address
    WebappHelper.getMailConfig("mailSupport"), // 4: direct link to change password workflow (e.g. https://xx.xx.xx/olat/url/changepw/0)
    changePwUrl };
    String subject = translator.translate("mail.pwd.subject", args);
    String body = translator.translate("mail.pwd.body", args);
    MailContext context = new MailContextImpl(null, null, "[Identity:" + identity.getKey() + "]");
    MailBundle bundle = new MailBundle();
    bundle.setContext(context);
    bundle.setToId(identity);
    bundle.setContent(subject, body);
    mailManager.sendMessage(bundle);
}
Also used : Locale(java.util.Locale) MailContextImpl(org.olat.core.util.mail.MailContextImpl) Translator(org.olat.core.gui.translator.Translator) MailContext(org.olat.core.util.mail.MailContext) MailBundle(org.olat.core.util.mail.MailBundle) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 65 with MailBundle

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

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)

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