public boolean isMailSendConfigOk() { getMailSessionLocalSettingsConfigModel(); return mailSendConfigOk; }
/** * @return true if at least a send mail host is given, otherwise false. */ @Override public boolean isSendMailConfigured() { return sendMailConfiguration != null && sendMailConfiguration.isMailSendConfigOk(); }
/** * For your convenience. Sets the subject and prepends the ProjectForge standard: "[ProjectForge] " * * @param subject */ public void setProjectForgeSubject(String subject) { this.subject = SendMail.getProjectForgeSubject(subject); }
@Test public void sendMailSyncWithIcalAndAttachmentTest() { when(mailSessionLocalSettingsConfigModel.isEmailEnabled()).thenReturn(true); when(mailSessionLocalSettingsConfigModel.getStandardEmailSender()).thenReturn("sender@test.de"); when(configurationService.createMailSessionLocalSettingsConfigModel()).thenReturn(mailSessionLocalSettingsConfigModel); when(configurationService.getSendMailConfiguration()).thenReturn(sendMailConfiguration); when(sendMailConfiguration.getCharset()).thenReturn("UTF-8"); final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); message.setContent(""); final String icalContent = "ABC"; final Collection<MailAttachment> attachments = new ArrayList<>(); when(attachment.getFilename()).thenReturn("test.abc"); sendMail.send(message, icalContent, attachments, false); }
@Test public void sendMailWithoutConfigTest() { final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); final String icalContent = null; final Collection<? extends MailAttachment> attachments = null; assertFalse(sendMail.send(message, icalContent, attachments)); }
private boolean sendMail(final String subject, final String content, final String recipientMailAddress, final String recipientRealName, final PFUserDO... additionalRecipients) { final Mail mail = new Mail(); mail.setContentType(Mail.CONTENTTYPE_HTML); mail.setSubject(subject); mail.setContent(content); if (StringUtils.isNotBlank(recipientMailAddress) && StringUtils.isNotBlank(recipientRealName)) { mail.setTo(recipientMailAddress, recipientRealName); } Arrays.stream(additionalRecipients).forEach(mail::setTo); return sendMailService.send(mail, null, null); }
/** * @param composedMessage the message to send * @param icalContent the ical content to add * @param attachments other attachments to add * @return true for successful sending, otherwise an exception will be thrown. * @throws UserException if to address is not given. * @throws InternalErrorException due to technical failures. */ public boolean send(final Mail composedMessage, final String icalContent, final Collection<? extends MailAttachment> attachments) { return send(composedMessage, icalContent, attachments, true); }
public void setTo(String mailAdress, String realName) { addTo(mailAdress); if (StringUtils.isBlank(getToRealname())) { setToRealname(realName); } }
private String getContent(final Part msg) throws MessagingException, IOException { final StringBuffer buf = new StringBuffer(); getContent(msg, buf); return buf.toString(); }
@Test public void sendMailSyncWithAttachmentTest() { when(mailSessionLocalSettingsConfigModel.isEmailEnabled()).thenReturn(true); when(mailSessionLocalSettingsConfigModel.getStandardEmailSender()).thenReturn("sender@test.de"); when(configurationService.createMailSessionLocalSettingsConfigModel()).thenReturn(mailSessionLocalSettingsConfigModel); when(configurationService.getSendMailConfiguration()).thenReturn(sendMailConfiguration); when(sendMailConfiguration.getCharset()).thenReturn("UTF-8"); final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); message.setContent(""); final String icalContent = null; final Collection<MailAttachment> attachments = new ArrayList<>(); when(attachment.getFilename()).thenReturn("test.abc"); attachments.add(attachment); sendMail.send(message, icalContent, attachments, false); }
@Test public void sendMailUserNullTest() { final Mail message = new Mail(); PFUserDO toUser = null; message.setTo(toUser); final String icalContent = null; final Collection<? extends MailAttachment> attachments = null; try { sendMail.send(message, icalContent, attachments); assertTrue(false); } catch (UserException e) { //OK } toUser = new PFUserDO(); message.setTo(toUser); try { sendMail.send(message, icalContent, attachments); assertTrue(false); } catch (UserException e) { //OK } }
@Test public void sendMailNullTest() { final Mail message = null; final String icalContent = null; final Collection<? extends MailAttachment> attachments = null; assertFalse(sendMail.send(message, icalContent, attachments)); }
public void setTo(PFUserDO user) { if (user == null || user.getEmail() == null) { log.warn("Could not set email receiver for PFUserDO. User or email is null."); return; } addTo(user.getEmail()); if (StringUtils.isBlank(getToRealname())) { setToRealname(user.getFullname()); } }
public String getDefaultSendMailAddress() { return getMailSessionLocalSettingsConfigModel().getDefaultEmailSender(); }
@Test public void sendMailSyncTest() { when(mailSessionLocalSettingsConfigModel.isEmailEnabled()).thenReturn(true); when(mailSessionLocalSettingsConfigModel.getStandardEmailSender()).thenReturn("sender@test.de"); when(configurationService.createMailSessionLocalSettingsConfigModel()).thenReturn(mailSessionLocalSettingsConfigModel); when(configurationService.getSendMailConfiguration()).thenReturn(sendMailConfiguration); when(sendMailConfiguration.getCharset()).thenReturn("UTF-8"); final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); message.setContent(""); final String icalContent = null; final Collection<? extends MailAttachment> attachments = null; sendMail.send(message, icalContent, attachments, false); }
@Test public void sendMailEmailDisabledTest() { when(configurationService.createMailSessionLocalSettingsConfigModel()).thenReturn(mailSessionLocalSettingsConfigModel); final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); final String icalContent = null; final Collection<? extends MailAttachment> attachments = null; assertFalse(sendMail.send(message, icalContent, attachments)); }
@Test public void sendMailSyncWithIcalTest() { when(mailSessionLocalSettingsConfigModel.isEmailEnabled()).thenReturn(true); when(mailSessionLocalSettingsConfigModel.getStandardEmailSender()).thenReturn("sender@test.de"); when(configurationService.createMailSessionLocalSettingsConfigModel()).thenReturn(mailSessionLocalSettingsConfigModel); when(configurationService.getSendMailConfiguration()).thenReturn(sendMailConfiguration); when(sendMailConfiguration.getCharset()).thenReturn("UTF-8"); final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); message.setContent(""); final String icalContent = "ABC"; final Collection<? extends MailAttachment> attachments = null; sendMail.send(message, icalContent, attachments, false); }
@Test public void sendMailAsyncTest() { when(mailSessionLocalSettingsConfigModel.isEmailEnabled()).thenReturn(true); when(configurationService.createMailSessionLocalSettingsConfigModel()).thenReturn(mailSessionLocalSettingsConfigModel); final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); final String icalContent = null; final Collection<? extends MailAttachment> attachments = null; assertTrue(sendMail.send(message, icalContent, attachments)); }
@Test public void sendMailEmptyConfigTest() { final MailSessionLocalSettingsConfigModel model = new MailSessionLocalSettingsConfigModel(); when(configurationService.createMailSessionLocalSettingsConfigModel()).thenReturn(model); final Mail message = new Mail(); final PFUserDO toUser = new PFUserDO(); toUser.setEmail("devnull@test.de"); message.setTo(toUser); final String icalContent = null; final Collection<? extends MailAttachment> attachments = null; assertFalse(sendMail.send(message, icalContent, attachments)); }