Example usage for org.springframework.mail SimpleMailMessage setText

List of usage examples for org.springframework.mail SimpleMailMessage setText

Introduction

In this page you can find the example usage for org.springframework.mail SimpleMailMessage setText.

Prototype

@Override
    public void setText(String text) 

Source Link

Usage

From source file:org.medici.bia.service.mail.MailServiceImpl.java

/**
 * {@inheritDoc}//from w w  w. ja v a  2 s .c  o  m
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public Boolean sendMailLockedUser(LockedUser lockedUser) {
    try {
        if (!StringUtils.isBlank(lockedUser.getUser().getMail())) {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(getMailFrom());
            message.setTo(lockedUser.getUser().getMail());
            message.setSubject(ApplicationPropertyManager.getApplicationProperty("mail.lockedUser.subject"));
            message.setText(
                    ApplicationPropertyManager.getApplicationProperty("mail.lockedUser.text",
                            new String[] { lockedUser.getUser().getAccount(),
                                    ApplicationPropertyManager.getApplicationProperty("mail.admin.to"), },
                            "{", "}"));
            getJavaMailSender().send(message);
            SimpleMailMessage messageToAdmin = new SimpleMailMessage();
            messageToAdmin.setFrom(getMailFrom());
            messageToAdmin.setTo(ApplicationPropertyManager.getApplicationProperty("mail.admin.to"));
            messageToAdmin.setSubject(
                    ApplicationPropertyManager.getApplicationProperty("mail.lockedUserToAdmin.subject"));
            messageToAdmin
                    .setText(ApplicationPropertyManager.getApplicationProperty("mail.lockedUserToAdmin.text",
                            new String[] { lockedUser.getUser().getAccount() }, "{", "}"));
            getJavaMailSender().send(messageToAdmin);
            lockedUser.setMailSended(Boolean.TRUE);
            lockedUser.setMailSendedDate(new Date());
            getLockedUserDAO().merge(lockedUser);
        } else {
            logger.error("Mail locked not sended for user " + lockedUser.getUser().getAccount()
                    + ". Check mail field on tblUser for account " + lockedUser.getUser().getAccount());
        }
        return Boolean.TRUE;
    } catch (Throwable throwable) {
        logger.error(throwable);
        return Boolean.FALSE;
    }
}

From source file:org.medici.bia.service.mail.MailServiceImpl.java

/**
 * {@inheritDoc}/*from www .j a  v a  2s.co  m*/
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public Boolean sendMailUnlockedUser(LockedUser lockedUser) {
    try {
        if (!StringUtils.isBlank(lockedUser.getUser().getMail())) {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(getMailFrom());
            message.setTo(lockedUser.getUser().getMail());
            message.setSubject(ApplicationPropertyManager.getApplicationProperty("mail.unlockedUser.subject"));
            message.setText(ApplicationPropertyManager.getApplicationProperty("mail.unlockedUser.text"));
            getJavaMailSender().send(message);

            lockedUser.setMailUnlockSended(Boolean.TRUE);
            lockedUser.setMailUnlockSendedDate(new Date());
            getLockedUserDAO().merge(lockedUser);
        } else {
            logger.error("Mail locked not sended for user " + lockedUser.getUser().getAccount()
                    + ". Check mail field on tblUser for account " + lockedUser.getUser().getAccount());
        }
        return Boolean.TRUE;
    } catch (Throwable throwable) {
        logger.error(throwable);
        return Boolean.FALSE;
    }
}

From source file:org.medici.bia.service.mail.MailServiceImpl.java

/**
 * {@inheritDoc}/*from   w  w  w  .  jav  a2s. c om*/
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public Boolean sendUserPasswordResetMail(PasswordChangeRequest passwordChangeRequest) {
    try {
        if (!StringUtils.isBlank(passwordChangeRequest.getUser().getMail())) {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(getMailFrom());
            message.setTo(passwordChangeRequest.getUser().getMail());
            message.setSubject(
                    ApplicationPropertyManager.getApplicationProperty("mail.resetUserPassword.subject"));
            message.setText(ApplicationPropertyManager.getApplicationProperty("mail.resetUserPassword.text",
                    new String[] { passwordChangeRequest.getUser().getFirstName(),
                            passwordChangeRequest.getUser().getAccount(),
                            URLEncoder.encode(passwordChangeRequest.getUuid().toString(), "UTF-8"),
                            ApplicationPropertyManager.getApplicationProperty("website.protocol"),
                            ApplicationPropertyManager.getApplicationProperty("website.domain"),
                            ApplicationPropertyManager.getApplicationProperty("website.contextPath") },
                    "{", "}"));
            getJavaMailSender().send(message);

            passwordChangeRequest.setMailSended(Boolean.TRUE);
            passwordChangeRequest.setMailSendedDate(new Date());
            getPasswordChangeRequestDAO().merge(passwordChangeRequest);
        } else {
            logger.error(
                    "Mail password reset not sended for user " + passwordChangeRequest.getUser().getAccount()
                            + ". Check mail field on tblUser for account "
                            + passwordChangeRequest.getUser().getAccount());
        }
        return Boolean.TRUE;
    } catch (Throwable throwable) {
        logger.error(throwable);
        return Boolean.FALSE;
    }
}

From source file:org.obiba.opal.shell.commands.ReportCommand.java

private void sendEmailNotification(ReportTemplate reportTemplate, FileObject reportOutput) {
    String reportTemplateName = reportTemplate.getName();

    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(fromAddress);/*from w  ww . ja  v  a2 s. c o m*/
    message.setSubject("[Opal] Report: " + reportTemplateName);
    message.setText(getEmailNotificationText(reportTemplate, reportOutput));

    for (String emailAddress : reportTemplate.getEmailNotificationAddresses()) {
        message.setTo(emailAddress);
        try {
            mailSender.send(message);
        } catch (MailException ex) {
            getShell().printf("Email notification not sent: %s", ex.getMessage());
            log.error("Email notification not sent: {}", ex.getMessage());
        }
    }
}

From source file:org.openlmis.core.service.UserService.java

private SimpleMailMessage createEmailMessage(User user, String resetPasswordLink, String subject) {
    String passwordResetToken = generateUUID();
    String[] passwordResetLink = new String[] { user.getFirstName(), user.getLastName(), user.getUserName(),
            resetPasswordLink + passwordResetToken };
    String mailBody = messageService.message("password.reset.email.body", (Object[]) passwordResetLink);

    userRepository.insertPasswordResetToken(user, passwordResetToken);

    SimpleMailMessage emailMessage = new SimpleMailMessage();
    emailMessage.setSubject(subject);/*from   w  w w.java 2s . co  m*/
    emailMessage.setText(mailBody);
    emailMessage.setTo(user.getEmail());

    return emailMessage;
}

From source file:org.opentestsystem.shared.monitoringalerting.service.AbstractNotificationService.java

private void sendNotifications(final List<Notification> notifications) {
    for (Notification notification : notifications) {
        notificationRepository.save(notification);

        if (this.emailActive) {
            SimpleMailMessage message = new SimpleMailMessage(); // NOPMD
            message.setFrom(this.fromAddress);
            message.setBcc(notification.getAddresses().toArray(new String[] {}));
            message.setSubject(subjectPrefix + " " + notification.getSubject());
            message.setText(notification.getContent());
            mailSender.send(message);//from   w w w. j  av  a2  s  .  c  o  m
        }
    }
}

From source file:org.orcid.core.manager.NotificationManagerTest.java

@Test
@Rollback/*from w w  w .j av a 2 s  .c  om*/
public void testSendLegacyVerificationEmail() throws JAXBException, IOException, URISyntaxException {
    URI baseUri = new URI("http://testserver.orcid.org");
    SecurityQuestionEntity securityQuestion = new SecurityQuestionEntity();
    securityQuestion.setId(1);
    securityQuestion.setQuestion("What is the name of your favorite teacher?");
    when(securityQuestionDao.find(1)).thenReturn(securityQuestion);

    OrcidMessage orcidMessage = (OrcidMessage) unmarshaller
            .unmarshal(getClass().getResourceAsStream(ORCID_INTERNAL_FULL_XML));
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    notificationManager.sendLegacyVerificationEmail(orcidProfile, baseUri);

    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("Open Researcher & Contributor ID - Registration Complete");
    expected.setText(
            IOUtils.toString(getClass().getResourceAsStream("example_legacy_verification_email_body.txt")));

    verify(mailSender, times(1)).send(expected);
}

From source file:org.orcid.core.manager.NotificationManagerTest.java

@Test
@Rollback/*from  ww  w  . j  a  v a  2  s  .co m*/
public void testSendVerificationEmail() throws JAXBException, IOException, URISyntaxException {
    URI baseUri = new URI("http://testserver.orcid.org");

    OrcidMessage orcidMessage = (OrcidMessage) unmarshaller
            .unmarshal(getClass().getResourceAsStream(ORCID_INTERNAL_FULL_XML));
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    notificationManager.sendVerificationEmail(orcidProfile, baseUri);

    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("Open Researcher & Contributor ID - Email Verification Required");
    expected.setText(IOUtils.toString(getClass().getResourceAsStream("example_verification_email_body.txt")));

    verify(mailSender, times(1)).send(expected);
}

From source file:org.orcid.core.manager.NotificationManagerTest.java

@Test
@Rollback/*from   w  ww  .  j  a va2 s.co  m*/
public void testResetEmail() throws Exception {
    URI baseUri = new URI("http://testserver.orcid.org");

    OrcidMessage orcidMessage = (OrcidMessage) unmarshaller
            .unmarshal(getClass().getResourceAsStream(ORCID_INTERNAL_FULL_XML));
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    orcidProfile.setPassword("r$nd0m");
    EncryptionManager mockEncypter = mock(EncryptionManager.class);
    getTargetObject(notificationManager, NotificationManagerImpl.class).setEncryptionManager(mockEncypter);
    when(mockEncypter.encryptForExternalUse(any(String.class))).thenReturn(
            "Ey+qsh7G2BFGEuqqkzlYRidL4NokGkIgDE+1KOv6aLTmIyrppdVA6WXFIaQ3KsQpKEb9FGUFRqiWorOfhbB2ww==");
    notificationManager.sendPasswordResetEmail(orcidProfile, baseUri);
    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("Open Researcher & Contributor ID - Password Reset");
    String expectedText = IOUtils.toString(getClass().getResourceAsStream("example_reset_email_body.txt"));
    expected.setText(expectedText);

    verify(mailSender, times(1)).send(expected);
}

From source file:org.orcid.core.manager.NotificationManagerTest.java

@Test
@Rollback/*from w ww.  j  a  v  a 2  s. co m*/
public void testAmendEmail() throws JAXBException, IOException, URISyntaxException {

    OrcidMessage orcidMessage = (OrcidMessage) unmarshaller
            .unmarshal(getClass().getResourceAsStream(ORCID_INTERNAL_FULL_XML));
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    notificationManager.sendAmendEmail(orcidProfile, "8888-8888-8888-8880");

    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("Open Researcher & Contributor ID - Record Amended");
    String expectedText = IOUtils.toString(getClass().getResourceAsStream("example_amend_email_body.txt"));
    expected.setText(expectedText);

    verify(mailSender, times(1)).send(expected);
}