Example usage for org.springframework.mail SimpleMailMessage getFrom

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

Introduction

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

Prototype

@Nullable
    public String getFrom() 

Source Link

Usage

From source file:ar.com.zauber.commons.spring.mail.AbstractMailSender.java

/** Creates a text representation for simpleMessages */
public static String toString(final SimpleMailMessage[] simpleMessages) {
    final StringBuilder sb = new StringBuilder();
    sb.append("This window show that the system tried to send an email.\n").append('\n')
            .append("The email wasnt sent. To do change the AppContext.\n");

    for (final SimpleMailMessage message : simpleMessages) {

        sb.append(" --------------8<--------------\n");

        if (message.getFrom() != null) {
            sb.append("From: ").append(message.getFrom());
        }//from www.  ja  v a2s .com
        if (message.getTo() != null) {
            sb.append("\nTo: ").append(Arrays.asList(message.getTo()));
        }
        if (message.getCc() != null) {
            sb.append("\nCc: ").append(Arrays.asList(message.getCc()));
        }
        if (message.getBcc() != null) {
            sb.append("\nBcc: ").append(Arrays.asList(message.getBcc()));
        }
        if (message.getReplyTo() != null) {
            sb.append("\nReply-To: ").append(message.getReplyTo());
        }
        if (message.getSentDate() != null) {
            sb.append("\nDate: ").append(message.getSentDate());
        }
        if (message.getSubject() != null) {
            sb.append("\nSubject: ").append(message.getSubject());
        }

        sb.append("\n\n").append(message.getText());
    }
    return sb.toString();
}

From source file:cherry.foundation.mail.SimpleMessageStoreTest.java

@Test
public void testGetMessage() {

    SimpleMessageStore store = new SimpleMessageStore();
    long id0 = store.createMessage("launcherId", "messageName", LocalDateTime.now(), "from@addr",
            asList("to@addr"), asList("cc@addr"), asList("bcc@addr"), "subject", "body");
    assertEquals(0L, id0);/*w w w.j  a va 2  s . c o m*/
    long id1 = store.createMessage("launcherId", "messageName", LocalDateTime.now().plusMinutes(1), "from@addr",
            asList("to@addr"), null, null, "subject", "body");
    assertEquals(1L, id1);

    SimpleMailMessage msg0 = store.getMessage(0L);
    assertNotNull(msg0);
    assertEquals("from@addr", msg0.getFrom());
    assertEquals(1, msg0.getTo().length);
    assertEquals("to@addr", msg0.getTo()[0]);
    assertEquals(1, msg0.getCc().length);
    assertEquals("cc@addr", msg0.getCc()[0]);
    assertEquals(1, msg0.getBcc().length);
    assertEquals("bcc@addr", msg0.getBcc()[0]);
    assertEquals("subject", msg0.getSubject());
    assertEquals("body", msg0.getText());

    assertNull(store.getMessage(10L));
}

From source file:com.springsource.greenhouse.account.WelcomeMailTransformerTest.java

@Test
public void welcomeMail() {
    WelcomeMailTransformer transformer = new WelcomeMailTransformer();

    Account account = new Account(1L, "Roy", "Clarkson", "rclarkson@vmware.com", "rclarkson",
            "http://foo.com/bar.jpg", new UriTemplate("http://greenhouse.springsource.org/members/{id}"));
    SimpleMailMessage welcomeMail = (SimpleMailMessage) transformer.welcomeMail(account);

    assertEquals("rclarkson@vmware.com", welcomeMail.getTo()[0]);
    assertEquals("Greenhouse <noreply@springsource.com>", welcomeMail.getFrom());
    assertEquals("Welcome to the Greenhouse!", welcomeMail.getSubject());
    String mailText = welcomeMail.getText();
    assertTrue(mailText.contains(//from ww w . j  a  v a2s .  co m
            "View your member profile at:" + NEWLINE + "http://greenhouse.springsource.org/members/rclarkson"));
}

From source file:ar.com.zauber.commons.spring.mail.RepositoryMailMessage.java

/** constructor de copia */
public RepositoryMailMessage(final SimpleMailMessage m) {
    setBcc(m.getBcc());//from  w ww.ja v  a  2  s .c o  m
    setCc(m.getCc());
    setFrom(m.getFrom());
    setReplyTo(m.getReplyTo());
    setSentDate(m.getSentDate());
    setSubject(m.getSubject());
    setText(m.getText());
    setTo(m.getTo());
}

From source file:com.gnizr.web.action.user.RequestPasswordReset.java

private boolean sendPasswordResetEmail(String token, User user) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("token", token);
    model.put("username", user.getUsername());
    model.put("gnizrConfiguration", getGnizrConfiguration());

    if (getVerifyResetTemplate() == null) {
        logger.error("RequestPasswordReset: templateMessge bean is not defined");
        addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG));
        return false;
    }/* w  w w .  j a v  a  2 s.  co m*/
    String toEmail = user.getEmail();
    if (toEmail == null) {
        logger.error("RequestPasswordReset: the email of user " + user.getUsername() + " is not defined");
        addActionError(String.valueOf(ActionErrorCode.ERROR_EMAIL_UNDEF));
        return false;
    }
    SimpleMailMessage msg = new SimpleMailMessage(getVerifyResetTemplate());
    msg.setTo(toEmail);

    if (msg.getFrom() == null) {
        String contactEmail = getGnizrConfiguration().getSiteContactEmail();
        if (contactEmail != null) {
            msg.setFrom(contactEmail);
        } else {
            msg.setFrom("help@localhost");
        }
    }

    Template fmTemplate = null;
    String text = null;
    try {
        fmTemplate = freemarkerEngine.getTemplate("login/notifyreset-template.ftl");
        text = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate, model);
    } catch (Exception e) {
        logger.error("RequestPasswordReset: error creating message template from Freemarker engine");
    }

    msg.setText(text);

    if (getMailSender() == null) {
        logger.error("RequestPasswordReset: mailSender bean is not defined");
        addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG));
        return false;
    }
    try {
        getMailSender().send(msg);
        return true;
    } catch (Exception e) {
        logger.error("RequestPasswordReset: send mail error. " + e);
        addActionError(String.valueOf(ActionErrorCode.ERROR_INTERNAL));
    }
    return false;
}

From source file:cs544.wamp_blog_engine.service.impl.NotificationService.java

@Override
public void contactAdmin(User user, String message) {
    SimpleMailMessage template = getToAdminTemplate();
    String emailMessage = String.format(template.getText(), message,
            user.getFirstname() + " " + user.getLastname());
    sendMail(user.getEmail(), template.getFrom(), template.getSubject(), emailMessage);
}

From source file:com.oak_yoga_studio.service.impl.NotificationServiceImpl.java

/**
 * Contact administrator/* ww w .j  a va2  s.  c o m*/
 * @param faculty
 * @param message 
 */
@Override
public void contactAdmin(Faculty faculty, String message) {
    SimpleMailMessage template = getToAdminTemplate();
    String emailMessage = String.format(template.getText(),
            faculty.getFirstName() + " " + faculty.getLastName(), message);
    sendMail(template.getFrom(), faculty.getEmail(), template.getSubject(), emailMessage);

}

From source file:com.oak_yoga_studio.service.impl.NotificationServiceImpl.java

/**
 * Notify customer//from   www . j  a  va 2s.c o m
 * @param customer
 * @param message
 */
@Override
public void notifyCustomer(Customer customer, String message) {
    SimpleMailMessage template = getToCustomersTemplate();
    String emailMessage = String.format(template.getText(),
            customer.getFirstName() + " " + customer.getLastName(), message);
    sendMail(template.getFrom(), customer.getEmail(), template.getSubject(), emailMessage);

}

From source file:cs544.wamp_blog_engine.service.impl.NotificationService.java

@Override
public void notifyBlogger(List<User> users, String message) {
    SimpleMailMessage template = getFromAdminTemplate();
    for (User user : users) {
        String emailMessage = String.format(template.getText(), user.getFirstname() + " " + user.getLastname(),
                message);//w  ww . j a  v a  2s  .  co m
        sendMail(template.getFrom(), user.getEmail(), template.getSubject(), emailMessage);
    }
}

From source file:com.oak_yoga_studio.service.impl.NotificationServiceImpl.java

/**
 * Begin email sending implementation, notify advisor
 * @param faculty//from   ww  w  .  jav  a2 s. c om
 * @param message 
 */

@Override
public void notifyAdvisor(Faculty faculty, String message) {

    SimpleMailMessage template = getToAdvisorTemplate();
    String emailMessage = String.format(template.getText(), message,
            faculty.getFirstName() + " " + faculty.getLastName());
    sendMail(faculty.getEmail(), template.getFrom(), template.getSubject(), emailMessage);

}