Search in sources :

Example 11 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class EmailServerUtil method newEmailToAddress.

static EmailItemBean newEmailToAddress(final EmailItemBean emailItem, final String toAddress) {
    final EmailItemBean expandedEmailItem;
    expandedEmailItem = new EmailItemBean(toAddress, emailItem.getFrom(), emailItem.getSubject(), emailItem.getBodyPlain(), emailItem.getBodyHtml());
    return expandedEmailItem;
}
Also used : EmailItemBean(password.pwm.bean.EmailItemBean)

Example 12 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class PwNotifyEngine method sendNoticeEmail.

private void sendNoticeEmail(final UserIdentity userIdentity) throws PwmUnrecoverableException {
    final Locale userLocale = PwmConstants.DEFAULT_LOCALE;
    final EmailItemBean emailItemBean = pwmApplication.getConfig().readSettingAsEmail(PwmSetting.EMAIL_PW_EXPIRATION_NOTICE, userLocale);
    final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, userLocale, SESSION_LABEL, userIdentity);
    final UserInfo userInfoBean = UserInfoFactory.newUserInfoUsingProxy(pwmApplication, SESSION_LABEL, userIdentity, userLocale);
    StatisticsManager.incrementStat(pwmApplication, Statistic.PWNOTIFY_EMAILS_SENT);
    pwmApplication.getEmailQueue().submitEmail(emailItemBean, userInfoBean, macroMachine);
}
Also used : Locale(java.util.Locale) EmailItemBean(password.pwm.bean.EmailItemBean) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo)

Example 13 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class AlertHandler method alertDailyStats.

public static void alertDailyStats(final PwmApplication pwmApplication, final Map<String, String> dailyStatistics) throws PwmUnrecoverableException {
    if (!checkIfEnabled(pwmApplication, PwmSetting.EVENTS_ALERT_DAILY_SUMMARY)) {
        return;
    }
    final Locale locale = PwmConstants.DEFAULT_LOCALE;
    for (final String toAddress : pwmApplication.getConfig().readSettingAsStringArray(PwmSetting.AUDIT_EMAIL_SYSTEM_TO)) {
        final String fromAddress = pwmApplication.getConfig().readAppProperty(AppProperty.AUDIT_EVENTS_EMAILFROM);
        final String subject = Display.getLocalizedMessage(locale, Display.Title_Application, pwmApplication.getConfig()) + " - Daily Summary";
        final StringBuilder textBody = new StringBuilder();
        final StringBuilder htmlBody = new StringBuilder();
        makeEmailBody(pwmApplication, dailyStatistics, locale, textBody, htmlBody);
        final EmailItemBean emailItem = new EmailItemBean(toAddress, fromAddress, subject, textBody.toString(), htmlBody.toString());
        LOGGER.debug("sending daily summary email to " + toAddress);
        pwmApplication.getEmailQueue().submitEmail(emailItem, null, MacroMachine.forNonUserSpecific(pwmApplication, null));
    }
}
Also used : Locale(java.util.Locale) EmailItemBean(password.pwm.bean.EmailItemBean)

Example 14 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class PasswordUtility method sendChangePasswordHelpdeskEmailNotice.

private static void sendChangePasswordHelpdeskEmailNotice(final PwmSession pwmSession, final PwmApplication pwmApplication, final UserInfo userInfo) throws PwmUnrecoverableException {
    final Configuration config = pwmApplication.getConfig();
    final Locale locale = pwmSession.getSessionStateBean().getLocale();
    final EmailItemBean configuredEmailSetting = config.readSettingAsEmail(PwmSetting.EMAIL_CHANGEPASSWORD_HELPDESK, locale);
    if (configuredEmailSetting == null) {
        LOGGER.debug(pwmSession, "skipping send change password email for '" + pwmSession.getUserInfo().getUserIdentity() + "' no email configured");
        return;
    }
    final MacroMachine macroMachine = userInfo == null ? null : MacroMachine.forUser(pwmApplication, pwmSession.getLabel(), userInfo, null);
    pwmApplication.getEmailQueue().submitEmail(configuredEmailSetting, userInfo, macroMachine);
}
Also used : Locale(java.util.Locale) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) Configuration(password.pwm.config.Configuration) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) EmailItemBean(password.pwm.bean.EmailItemBean) MacroMachine(password.pwm.util.macro.MacroMachine)

Example 15 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class EmailQueueManagerTest method testConvertEmailItemToMessage.

@Test
public void testConvertEmailItemToMessage() throws MessagingException, IOException {
    EmailService emailService = new EmailService();
    Configuration config = Mockito.mock(Configuration.class);
    Mockito.when(config.readAppProperty(AppProperty.SMTP_SUBJECT_ENCODING_CHARSET)).thenReturn("UTF8");
    EmailItemBean emailItemBean = new EmailItemBean("fred@flintstones.tv, barney@flintstones.tv", "bedrock-admin@flintstones.tv", "Test Subject", "bodyPlain", "bodyHtml");
    EmailServer emailServer = EmailServer.builder().javaMailProps(new Properties()).build();
    List<Message> messages = EmailServerUtil.convertEmailItemToMessages(emailItemBean, config, emailServer);
    Assert.assertEquals(2, messages.size());
    Message message = messages.get(0);
    Assert.assertEquals(new InternetAddress("fred@flintstones.tv"), message.getRecipients(Message.RecipientType.TO)[0]);
    Assert.assertEquals(new InternetAddress("bedrock-admin@flintstones.tv"), message.getFrom()[0]);
    Assert.assertEquals("Test Subject", message.getSubject());
    String content = IOUtils.toString(message.getInputStream());
    Assert.assertTrue(content.contains("bodyPlain"));
    Assert.assertTrue(content.contains("bodyHtml"));
    message = messages.get(1);
    Assert.assertEquals(new InternetAddress("barney@flintstones.tv"), message.getRecipients(Message.RecipientType.TO)[0]);
    Assert.assertEquals(new InternetAddress("bedrock-admin@flintstones.tv"), message.getFrom()[0]);
    Assert.assertEquals("Test Subject", message.getSubject());
    content = IOUtils.toString(message.getInputStream());
    Assert.assertTrue(content.contains("bodyPlain"));
    Assert.assertTrue(content.contains("bodyHtml"));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Configuration(password.pwm.config.Configuration) EmailItemBean(password.pwm.bean.EmailItemBean) Message(javax.mail.Message) EmailServer(password.pwm.svc.email.EmailServer) EmailService(password.pwm.svc.email.EmailService) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

EmailItemBean (password.pwm.bean.EmailItemBean)25 Configuration (password.pwm.config.Configuration)16 Locale (java.util.Locale)14 FormConfiguration (password.pwm.config.value.data.FormConfiguration)11 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)9 MacroMachine (password.pwm.util.macro.MacroMachine)9 UserInfo (password.pwm.ldap.UserInfo)8 Map (java.util.Map)5 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)5 TreeMap (java.util.TreeMap)4 PwmApplication (password.pwm.PwmApplication)4 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)3 PwmSession (password.pwm.http.PwmSession)3 Instant (java.time.Instant)2 LinkedHashMap (java.util.LinkedHashMap)2 UserIdentity (password.pwm.bean.UserIdentity)2 MessageSendMethod (password.pwm.config.option.MessageSendMethod)2 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 ArrayList (java.util.ArrayList)1