Example usage for org.springframework.mail SimpleMailMessage SimpleMailMessage

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

Introduction

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

Prototype

public SimpleMailMessage(SimpleMailMessage original) 

Source Link

Document

Copy constructor for creating a new SimpleMailMessage from the state of an existing SimpleMailMessage instance.

Usage

From source file:com.badgersoft.eseoprocessor.service.MailServiceImpl.java

public void sendAlertMail(String alert) {

    SimpleMailMessage mailMessage = new SimpleMailMessage(alertMailMessage);
    mailMessage.setText(alert);//  w  w w  . ja v  a 2s .co m
    mailSender.send(mailMessage);

}

From source file:org.homiefund.api.support.MailServiceImpl.java

@Override
@Async/*  w ww. j  a  v a2 s  .  c  o m*/
public void sendInvite(InvitationDTO invitationDTO, String email) {
    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    msg.setTo(email);
    msg.setText(invitationDTO.getHash());

    try {
        mailSender.send(msg);
    } catch (MailException e) {
        log.fatal(e);
    }
}

From source file:org.jasig.portlets.FeedbackPortlet.service.EmailForwardingListener.java

public void performAction(FeedbackItem item) {

    // only forward on email with comments
    if (item.getFeedback() == null || item.getFeedback().equals(""))
        return;//from w ww  .jav a2s  . c  o  m

    SimpleMailMessage message = new SimpleMailMessage(mailMessage);

    // set the user's email address as the from and reply to
    if (item.getUseremail() != null && !item.getUseremail().equals("")) {
        message.setFrom(item.getUseremail());
        message.setReplyTo(item.getUseremail());
    }

    // construct the message text
    String text = message.getText();
    if (item.getUsername() != null && !item.getUsername().equals(""))
        text = StringUtils.replace(text, "%USERNAME%", item.getUsername());
    else
        text = StringUtils.replace(text, "%USERNAME%", "Anonymous");

    if (item.getUserrole() != null && !item.getUserrole().equals(""))
        text = StringUtils.replace(text, "%USERROLE%", item.getUserrole());
    else
        text = StringUtils.replace(text, "%USERROLE%", "unknown");

    text = StringUtils.replace(text, "%USERAGENT%", item.getUseragent());

    if (item.getTabname() != null && !item.getTabname().equals(""))
        text = StringUtils.replace(text, "%TABNAME%", item.getTabname());
    else
        text = StringUtils.replace(text, "%TABNAME%", "none");

    text = StringUtils.replace(text, "%FEEDBACKTYPE%", item.getFeedbacktype());
    text = StringUtils.replace(text, "%FEEDBACK%", item.getFeedback());
    message.setText(text);

    // send the message
    mailSender.send(message);

}

From source file:com.example.securelogin.domain.service.mail.PasswordReissueMailSharedServiceImpl.java

@Override
public void send(String to, String text) {
    SimpleMailMessage message = new SimpleMailMessage(templateMessage);
    message.setTo(to);//  w  ww .  jav a2 s .co m
    message.setText(text);
    mailSender.send(message);
}

From source file:com.healthcit.cacure.utils.MailSendingService.java

/**
 * Sends a notification email, that a section has been submitted for review
 *
 * @param form the form, which is submitted for review
 * @param toEmail the recipient - the intended recipients are ROLE_APPROVERs
 *///  ww w.  j a  v a 2 s .  co m
public void sendSubmittedSectionNotification(QuestionnaireForm form, String toEmail, String webAppUri) {
    SimpleMailMessage message = new SimpleMailMessage(submittedSectionNotificationTemplate);

    StringBuilder emailText = new StringBuilder(submittedSectionNotificationTemplate.getText());
    //TODO: DEVISE A BETTER WAY OF OBTAINING THE WEB-APP PATH
    StringUtils.replace(emailText, WEB_APP_PATH_IDENTIFIER, webAppUri);
    StringUtils.replace(emailText, MODULE_ID_IDENTIFIER, form.getModule().getId().toString());
    StringUtils.replace(emailText, FORM_ID_IDENTIFIER, form.getId().toString());

    message.setText(emailText.toString());
    message.setTo(toEmail);

    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Sending section submitted notification mail to " + toEmail);
        }

        mailSender.send(message);

    } catch (MailException me) {
        logger.error("Failed sending section submitted notification mail", me);
    }
}

From source file:org.cloudbyexample.dc.service.si.notification.NotificationProcessor.java

public void process(Application application, @Header(PROVISION_HEADER) ProvisionTask task) {
    for (Notification notification : task.getNotifications()) {
        SimpleMailMessage msg = new SimpleMailMessage(simpleMailMessageg);
        msg.setSubject("Docker Control Provision Notification");
        msg.setTo(notification.getEmail());

        Map<String, Object> vars = new HashMap<String, Object>();
        vars.put("application", application);
        vars.put("task", task);

        sender.send(msg, PROVISION_TEMPLATE, vars);

        logger.debug("Sent provision message to '{}' for '{}'.  id={}", notification.getEmail(),
                application.getName(), task.getId());
    }//  www.  ja  v  a 2 s .  c  om
}

From source file:fm.last.citrine.notification.EMailNotifier.java

/**
 * Creates a mail message which is ready to be sent.
 * //from  w w  w .  j a v  a2 s.  c  o  m
 * @param recipients Message recipients.
 * @param taskRun Task run containing various values which will be put into message.
 * @param taskName The task name.
 * @return A prepared mail message.
 */
private SimpleMailMessage createMessage(String recipients, TaskRun taskRun, String taskName) {
    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    if (!StringUtils.isEmpty(recipients)) {
        // override default recipients set in application context
        String[] recipientArray = recipients.split(",");
        msg.setTo(recipientArray);
    }
    msg.setSubject("[citrine] '" + taskName + "' finished with Status " + taskRun.getStatus() + " for TaskRun "
            + taskRun.getId());
    StringBuilder messageText = new StringBuilder();

    String logUrl = getDisplayLogUrl(taskRun);
    if (logUrl != null) {
        messageText.append("\nSee: ").append(logUrl).append("\n");
    }

    if (!StringUtils.isEmpty(taskRun.getStackTrace())) {
        messageText.append("\nStackTrace:\n").append(taskRun.getStackTrace()).append("\n");
    }
    if (!StringUtils.isEmpty(taskRun.getSysErr())) {
        messageText.append("\nSysErr:\n").append(taskRun.getSysErr()).append("\n");
    }
    if (!StringUtils.isEmpty(taskRun.getSysOut())) {
        messageText.append("\nSysOut:\n").append(taskRun.getSysOut()).append("\n");
    }
    msg.setText(messageText.toString());

    log.warn(messageText.toString());

    return msg;
}

From source file:example.web.EmailController.java

private String sendMail(String subject) {
    String results = "Failed to send message: ";
    try {/*from  www.j a v a  2  s . c om*/
        SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
        msg.setSubject(subject);
        this.mailSender.send(msg);
        results = "Sent message with subject '" + subject + "'!";
    } catch (MailException ex) {
        results += ex.getMessage();
        System.err.println(results);
        ex.printStackTrace();
    }
    return results;
}

From source file:com.mycompany.capstone.dao.QuoteDaoDbImpl.java

@Override
public Quote create(Quote quote) {

    jdbcTemplate.update(SQL_INSERT_QUOTE, quote.getFirstName(), quote.getLastName(), quote.getEmail(),
            quote.getYear(), quote.getSelectedMake(), quote.getSelectedModel(), quote.getDescription());

    Integer id = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Integer.class);

    quote.setId(id);/*from w w w  . j  ava 2s .c om*/

    Properties props = (Properties) System.getProperties().clone();
    props.put("mail.smtp.host", "host");
    props.setProperty("mail.smtp.port", "587");
    props.put("mail.smtp.auth", true);

    //Bypass the SSL authentication
    props.put("mail.smtp.ssl.enable", false);
    props.put("mail.smtp.starttls.enable", false);

    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    msg.setTo("bennettglob@gmail.com");
    //        msg.setRecipients(Message.RecipientType.TO, ("bennettglob@gmail.com" + quote.getEmail()));

    msg.setText("test");
    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        // simply log it and go on...
        System.err.println(ex.getMessage());
    }

    return quote;

}

From source file:it.tai.solr.services.impl.SolrSummaryServiceImpl.java

private void sendPreConfiguredMail(String message, SimpleMailMessage simpleMailMessage) {
    SimpleMailMessage mailMessage = new SimpleMailMessage(simpleMailMessage);
    mailMessage.setText(message);/*w  w w  . j a  v a  2s .co m*/
    mailSender.send(mailMessage);
}