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.orcid.core.manager.NotificationManagerTest.java

@Test
@Rollback/*from   w w  w  . ja  v a 2 s .c  o  m*/
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {

    OrcidMessage orcidMessage = (OrcidMessage) unmarshaller
            .unmarshal(getClass().getResourceAsStream(ORCID_INTERNAL_FULL_XML));
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    DelegationDetails firstNewDelegate = new DelegationDetails();
    DelegateSummary firstNewDelegateSummary = new DelegateSummary();
    firstNewDelegateSummary.setCreditName(new CreditName("Jimmy Dove"));
    firstNewDelegate.setDelegateSummary(firstNewDelegateSummary);

    DelegationDetails secondNewDelegate = new DelegationDetails();
    DelegateSummary secondNewDelegateSummary = new DelegateSummary();
    secondNewDelegate.setDelegateSummary(secondNewDelegateSummary);

    notificationManager.sendNotificationToAddedDelegate(orcidProfile,
            Arrays.asList(new DelegationDetails[] { firstNewDelegate }));

    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("Open Researcher & Contributor ID - You've been Made a Proxy!");
    String expectedText = IOUtils
            .toString(getClass().getResourceAsStream("example_added_as_delegate_email.txt"));
    expected.setText(expectedText);

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

    notificationManager.sendNotificationToAddedDelegate(orcidProfile,
            Arrays.asList(new DelegationDetails[] { firstNewDelegate, secondNewDelegate }));
    // check that the mail sender has been called an additional two times
    // because we've added a second delegate
    verify(mailSender, times(3)).send(any(SimpleMailMessage.class));

}

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

@Test
@Rollback/*from  www .  ja  va  2s .  c  o m*/
public void testSendDeactivateEmail() throws JAXBException, IOException, URISyntaxException {
    OrcidMessage orcidMessage = (OrcidMessage) unmarshaller
            .unmarshal(getClass().getResourceAsStream(ORCID_INTERNAL_FULL_XML));
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    notificationManager.sendOrcidDeactivateEmail(orcidProfile, new URI("http://testserver.orcid.org"));

    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("Open Researcher & Contributor ID - Request to Deactivate Your Orcid Account");
    String expectedText = IOUtils
            .toString(getClass().getResourceAsStream("example_deactivate_orcid_email.txt"));
    expected.setText(expectedText);

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

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

@Test
@Rollback//from  www.  j ava  2s  . c o m
public void testApiCreatedRecordEmail() throws JAXBException, IOException, URISyntaxException {

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

    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("ORCID - Claim your ORCID Account");
    String expectedText = IOUtils
            .toString(getClass().getResourceAsStream("example_api_record_creation_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  w w. j a v  a 2 s. c  om*/
public void testClaimReminderEmail() throws JAXBException, IOException, URISyntaxException {

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

    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setFrom("no_reply@orcid.org");
    expected.setTo("josiah_carberry@brown.edu");
    expected.setSubject("ORCID - Reminder to claim your ORCID Account");
    String expectedText = IOUtils
            .toString(getClass().getResourceAsStream("example_claim_reminder_email_body.txt"));
    expected.setText(expectedText);

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

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

@Test
public void testChangeEmailAddress() throws Exception {
    OrcidMessage orcidMessage = (OrcidMessage) unmarshaller
            .unmarshal(getClass().getResourceAsStream(ORCID_INTERNAL_FULL_XML));
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    Email originalEmail = new Email("original@email.com");
    notificationManager.sendEmailAddressChangedNotification(orcidProfile, originalEmail,
            new URI("http://testserver.orcid.org"));

    SimpleMailMessage deactivateMessage = new SimpleMailMessage();
    deactivateMessage.setFrom("support@orcid.org");
    deactivateMessage.setTo("original@email.com");
    deactivateMessage.setSubject("ORCID - Your email has been successfully changed");
    String expectedText = IOUtils.toString(getClass().getResourceAsStream("example_deactivated_email.txt"));
    deactivateMessage.setText(expectedText);

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

    verify(mailSender, times(1)).send(newMessage);
    verify(mailSender, times(1)).send(deactivateMessage);
}

From source file:org.sipfoundry.sipxconfig.admin.mail.MailSenderContextImpl.java

public void sendMail(String to, String from, String subject, String body) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(getFullAddress(from));//from w w w .ja  v a 2 s .  co m
    msg.setFrom(getFullAddress(from));
    msg.setSubject(subject);
    msg.setText(body);
    msg.setSentDate(new Date());
    try {
        m_mailSender.send(msg);
    } catch (MailException e) {
        LOG.error(e);
    }

}

From source file:org.sipfoundry.sipxconfig.mail.MailSenderContextImpl.java

public void sendMail(String to, String from, String subject, String body) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(getFullAddress(to));//  w w  w  .  ja v a  2s  .co m
    msg.setFrom(getFullAddress(from));
    msg.setSubject(subject);
    msg.setText(body);
    msg.setSentDate(new Date());
    try {
        m_mailSender.send(msg);
    } catch (MailException e) {
        LOG.error(e);
    }

}

From source file:org.springframework.data.hadoop.admin.examples.EmailNotification.java

@Override
public void afterJob(JobExecution jobExecution) {
    logger.info("afterJob enter");
    SimpleMailMessage message = new SimpleMailMessage(templateMessage);
    message.setSubject("Spring Batch Job Status");
    message.setText("Job " + jobExecution.getJobInstance().getJobName() + " completed. Status is: "
            + jobExecution.getStatus());
    try {/*w w w  . j a v a 2s  .c o m*/
        mailSender.send(message);
    } catch (Throwable t) {
        logger.error("send mail failed", t);
    }
    logger.info("sent mail");
}

From source file:org.uhp.portlets.news.service.NotificationServiceImpl.java

private void sendDailyEmailForTopics(final Category category) {

    final List<Topic> topicsForToday = this.getPendingTopics(category.getCategoryId());

    if (topicsForToday.size() < 1) {
        return;/*from   w  ww  .ja v  a  2  s.c  o  m*/
    }

    final List<IEscoUser> managers = this.getOnlyTopicManagersForTopics(category.getCategoryId(),
            topicsForToday);

    if (managers.isEmpty()) {
        return;
    }
    for (IEscoUser user : managers) {
        if (user.getEmail() != null && user.getEmail().length() > 0) {
            SimpleMailMessage message = new SimpleMailMessage(templateMessage);
            message.setTo(user.getEmail());
            String text = message.getText();
            List<Topic> userTopics = filterUserTopics(user, topicsForToday);
            String[] tIds = new String[userTopics.size()];
            StringBuilder sb = new StringBuilder();
            int i = 0;
            for (Topic t : userTopics) {
                tIds[i++] = String.valueOf(t.getTopicId());
                sb.append(t.getName());
                sb.append(" [");
                int k = itemDao.getPendingItemsCountByTopic(t.getTopicId());
                sb.append(k + "]\n");

            }

            text = StringUtils.replace(text, "%NB%",
                    Integer.toString(this.itemDao.getPendingItemsCountByTopics(tIds)));
            text = StringUtils.replace(text, "%CATEGORY%", category.getName());
            text = StringUtils.replace(text, "%TOPICS%", sb.toString());
            message.setText(text);

            try {
                LOG.debug(message);
                this.mailSender.send(message);
            } catch (MailException e) {
                LOG.error("Notification Service:: An exception occured when sending mail, "
                        + "have you correctly configured your mail engine ?" + e);

            }
        }
    }

}

From source file:org.uhp.portlets.news.service.NotificationServiceImpl.java

private void sendDailyEmailForCategory(final Category category) {
    Long cId = category.getCategoryId();
    String n = "";
    LOG.debug("sendDailyEmailForCategory " + category.getName());
    List<Topic> topicsForToday = this.getPendingTopics(cId);
    if (topicsForToday.size() < 1) {
        LOG.debug("send Daily Email For Category [" + category.getName()
                + "] : nothing new, no notification sent");
        return;//  w  w  w. j a va2s . c  o  m
    }
    Set<IEscoUser> managers = this.getManagersForCategory(category);

    if (managers.isEmpty()) {
        return;
    }

    try {
        n = Integer.toString(this.itemDao.getPendingItemsCountByCategory(category.getCategoryId()));
    } catch (DataAccessException e1) {
        LOG.error("Notification error : " + e1.getMessage());

    }
    SimpleMailMessage message = new SimpleMailMessage(templateMessage);
    LOG.debug("send Daily Email For Category [" + category.getName() + "] : status OK");
    String[] recip = new String[managers.size()];
    int nb = 0;
    for (IEscoUser user : managers) {
        if (user.getEmail() != null && user.getEmail().length() > 0) {
            recip[nb++] = user.getEmail();
        }
    }

    message.setTo(recip);

    String text = message.getText();
    text = StringUtils.replace(text, "%NB%", n);
    text = StringUtils.replace(text, "%CATEGORY%", category.getName());
    text = StringUtils.replace(text, "%TOPICS%", this.getPendingTopicsForCategory(cId));
    message.setText(text);

    try {
        LOG.info(message);
        mailSender.send(message);
    } catch (MailException e) {
        LOG.error("Notification Service:: An exception occured when sending mail,"
                + " have you correctly configured your mail engine ?" + e);
    }

}