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;
}
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);
}
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));
}
}
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);
}
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"));
}
Aggregations