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.openmrs.contrib.metadatarepository.service.MailEngine.java

/**
 * Send a simple message based on a Velocity template.
 * @param msg the message to populate//from  w  w  w.  j a v a  2s.c om
 * @param templateName the Velocity template to use (relative to classpath)
 * @param model a map containing key/value pairs
 */
public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
        result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, model);
    } catch (VelocityException e) {
        e.printStackTrace();
        log.error(e.getMessage());
    }

    msg.setText(result);
    send(msg);
}

From source file:jp.xet.uncommons.wicket.utils.ErrorReportRequestCycleListener.java

@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
    if (ex instanceof PageExpiredException || ex instanceof StalePageException) {
        return null;
    }//from  w w w  . j ava2s  .  c o m

    if (ex instanceof WicketRuntimeException) {
        Throwable rootCause = getRootCause(ex);
        if (rootCause == null) {
            rootCause = ex;
        }

        String environment = loadEnvironment();
        if (enabledEnvironments == null || environment == null
                || ObjectUtils.containsElement(enabledEnvironments, environment)) {
            String type = rootCause.getClass().getSimpleName();
            String message = rootCause.getMessage();
            String subject = MessageFormat.format(subjectPattern, environment, type, message);

            SimpleMailMessage mailMessage = new SimpleMailMessage();
            mailMessage.setFrom(from);
            mailMessage.setTo(to);
            mailMessage.setSubject(subject);
            mailMessage.setText(getStackTrace(ex));
            try {
                logger.debug("sending exception report mail...");
                mailSender.send(mailMessage);
                logger.debug("success to send exception report mail");
            } catch (MailException e) {
                logger.error("failed to send exception report mail", e);
            }
        } else {
            logger.debug(
                    "exception report mail was not sent, "
                            + "because enabledEnvironments{} does not contain environment[{}]",
                    new Object[] { Arrays.toString(enabledEnvironments), environment });
        }
    }
    return null;
}

From source file:org.openhie.openempi.service.MailEngine.java

/**
 * Send a simple message based on a Velocity template.
 * @param msg the message to populate//  w w w .j a  v a 2s  . c  o m
 * @param templateName the Velocity template to use (relative to classpath)
 * @param model a map containing key/value pairs
 */
@SuppressWarnings("unchecked")
public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
        result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, model);
    } catch (VelocityException e) {
        e.printStackTrace();
        log.error(e.getMessage());
    }

    msg.setText(result);
    send(msg);
}

From source file:edu.txstate.dmlab.clusteringwiki.web.LoginController.java

@RequestMapping("reminder.*")
public void sendReminder(HttpServletRequest request, HttpServletResponse response, Model model) {
    // send an email with link to allow changing password
    String action = request.getParameter("applAction");
    if (action != null && action.equals("sendReminder") && isAjaxRequest(request)) {
        //requesting registration
        String email = request.getParameter("email");

        if (email == null) {
            sendOutput(response, "{\"error\":\"Invalid reminder request received.\"}");
            return;
        }//from  w w w .j a va  2  s  .com

        email = email.toLowerCase();

        IUserDao dao = applicationUser.getUserDao();

        User user = dao.selectUserByEmail(email);
        if (user == null) {
            sendOutput(response, "{\"error\":\"Invalid email.  Please try again.\"}");
            return;
        }

        //create password request link
        CredentialsRequest cred = new CredentialsRequest();
        cred.setEmail(email);
        String link = request.getRequestURL().toString();
        link = link.replace("reminder.html", "changePassword.html?key=" + cred.getKey());

        //Create a thread safe "sandbox" of the mailMessage
        SimpleMailMessage msg = new SimpleMailMessage(mailMessage);
        msg.setTo(email);
        msg.setText("Dear " + user.getFirstName() + ", \n\n"
                + "We have received a forgot password request at ClusteringWiki for the account "
                + "associated with this email address.  If you did not initiate this request, please "
                + "ignore this email message.  Otherwise, copy and paste the link below in your "
                + "browser to complete your password reset.  Please note this forgot pasword request "
                + "will expire in one hour. \n\n " + link + "\n\nThank you,\n\nClusterWiki Admin");
        try {
            mailSender.send(msg);
        } catch (MailException ex) {
            if (ex.contains(com.sun.mail.smtp.SMTPAddressFailedException.class)) {
                sendOutput(response,
                        "{\"error\":\"The email address is no longer valid.  Please contact an administrator or create a new account.\"}");
            } else if (ex.contains(com.sun.mail.smtp.SMTPSendFailedException.class)) {
                //ignore not being able to send this message out.
                sendOutput(response,
                        "{\"error\":\"Email message could not be sent.  Please try again later.\"}");
            } else
                sendOutput(response, "{\"error\":\"Email message could not be sent: <br><br>"
                        + StringEscapeUtils.escapeJavaScript(ex.getMessage().replace("\n", "<br>")) + "\"}");
            return;
        }

        //make valid and save credentials request
        cred.setValid(1);
        try {
            credentialsRequestDao.saveCredentialsRequest(cred);
        } catch (Exception e) {
            sendOutput(response, "{\"error\":\"Credential request could not be saved.  Please try again.\"}");
            return;
        }

        sendOutput(response, "{\"success\":true}");
        return;
    }
}

From source file:org.musicrecital.service.MailEngine.java

/**
 * Send a simple message based on a Velocity template.
 * @param msg the message to populate//from   w  w  w .  ja  v a 2s.com
 * @param templateName the Velocity template to use (relative to classpath)
 * @param model a map containing key/value pairs
 */
public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
        result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, "UTF-8", model);
    } catch (VelocityException e) {
        e.printStackTrace();
        log.error(e.getMessage());
    }

    msg.setText(result);
    send(msg);
}

From source file:edu.txstate.dmlab.clusteringwiki.web.RegisterController.java

@RequestMapping("register.*")
public String getRegisterPage(HttpServletRequest request, HttpServletResponse response, Model model) {

    String action = request.getParameter("applAction");
    if (action != null && action.equals("register") && isAjaxRequest(request)) {
        //requesting registration
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        String firstName = request.getParameter("firstname");
        String lastName = request.getParameter("lastname");

        if (email == null || password == null) {
            sendOutput(response, "{\"error\":\"Invalid registration request received.\"}");
            return null;
        }//from  ww  w. java 2  s  .co  m

        email = email.toLowerCase();

        IUserDao dao = applicationUser.getUserDao();

        User user = dao.selectUserByEmail(email);
        if (user != null) {
            sendOutput(response,
                    "{\"error\":\"An account is already registered with this "
                            + "email. Please use the forgot password feature to retrieve your credentials "
                            + "or choose an alternate email address.\"}");
            return null;
        }

        //Create a thread safe "sandbox" of the mailMessage
        SimpleMailMessage msg = new SimpleMailMessage(mailMessage);
        msg.setSubject("ClusteringWiki account created");
        msg.setTo(email);
        msg.setText("Dear " + firstName + ", \n\n"
                + "A ClusteringWiki account has been created for this email address.  Log in to ClusteringWiki to "
                + "start editing search result clusters.  Right-click on nodes to access available "
                + "editing operations.  Your edits will improve search for you as well as others "
                + "quering similar things.  \n\n " + "\n\nThank you,\n\nClusteringWiki Admin");
        try {
            mailSender.send(msg);
        } catch (MailException ex) {
            if (ex.contains(com.sun.mail.smtp.SMTPAddressFailedException.class)) {
                sendOutput(response,
                        "{\"error\":\"Invalid email address.  Please specify a valid email address.\"}");
            } else if (!ex.contains(com.sun.mail.smtp.SMTPSendFailedException.class)) {
                //ignore not being able to send this message out.
                sendOutput(response, "{\"error\":\"Email message could not be sent: <br><br>"
                        + StringEscapeUtils.escapeJavaScript(ex.getMessage().replace("\n", "<br>")) + "\"}");
            }
            return null;
        }

        user = new User();
        user.setEmail(email);
        user.setPassword(password);
        user.setFirstName(firstName);
        user.setLastName(lastName);
        try {
            dao.saveUser(user);
        } catch (Exception e) {
            sendOutput(response, "{\"error\":\"Registration failed: " + e.getMessage() + ".\"}");
            return null;
        }

        applicationUser.setEmail(email);
        applicationUser.setPassword(password);
        try {
            applicationUser.logIn();
        } catch (Exception e) {
            sendOutput(response, "{\"error\":\"Login error: " + e.getMessage() + "\"}");
            return null;
        }

        sendOutput(response, "{\"success\":true}");
        return null;
    }

    return "register";
}

From source file:mx.unam.pixel.controller.UsuarioController.java

public void recuperaContrasena() {
    List<Usuario> u = usuarioService.findByCorreo(correoRecuperar);
    if (u != null || u.size() > 0) {
        //Aqui se envia correo al usuario investigar si se regresaria null o la lista vacia

        SimpleMailMessage mail = new SimpleMailMessage();

        mail.setTo(u.get(0).getCorreo());
        mail.setFrom("pixel.is.pruebas@gmail.com");
        mail.setSubject("Muffin");
        mail.setCc("pixel_developer@gmail.com");
        mail.setText("Tu contrasea es :" + u.get(0).getContrasena());

        mailSender.send(mail);//from w  w  w. j a v a2  s. c om

    }
    return;
}

From source file:in.mycp.controller.LoginController.java

public void sendMessage(String mailFrom, String subject, String mailTo, String message) {
    org.springframework.mail.SimpleMailMessage mailMessage = new org.springframework.mail.SimpleMailMessage();
    mailMessage.setFrom(mailFrom);//from   ww w  . j a v a  2s  . c  om
    mailMessage.setSubject(subject);
    mailMessage.setTo(mailTo);
    mailMessage.setText(message);
    mailTemplate.send(mailMessage);
}

From source file:com.springsource.greenhouse.signup.WelcomeMailTransformer.java

/**
 * Perform the Account to MailMessage transformation.
 *///from w w w.j av  a2 s. co  m
@Transformer
public MailMessage welcomeMail(Account account) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setFrom("Greenhouse <noreply@springsource.com>");
    mailMessage.setTo(account.getEmail());
    mailMessage.setSubject("Welcome to the Greenhouse!");
    StringTemplate textTemplate;
    textTemplate = welcomeTemplateFactory.getStringTemplate();
    textTemplate.put("firstName", account.getFirstName());
    textTemplate.put("profileUrl", account.getProfileUrl());
    mailMessage.setText(textTemplate.render());
    return mailMessage;
}

From source file:org.benassi.bookeshop.web.interceptors.ConfirmationEmailInterceptor.java

@Override
public String intercept(ActionInvocation invocation) throws Exception {

    invocation.invoke();//  w  ww  . j  a  v a 2 s . c o m

    Map<String, Object> session = ActionContext.getContext().getSession();
    loggedCustomer = (Customer) session.get(BookeshopConstants.SESSION_USER);

    Order order = ((CheckoutAction) invocation.getAction()).getOrder();
    order.setFormattedDate(orderUtil.formatDate(order.getDate()));
    order.setFormattedTotal(orderUtil.formatTotal(order.getTotal()));
    Map model = new HashMap();
    model.put("customer", loggedCustomer);
    model.put("order", order);

    String result = null;
    try {
        result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "velocity/orderConfirmation.vm",
                model);
    } catch (VelocityException e) {
        logger.error("Error in generating confirmation email from velocity template.", e);
        return Action.ERROR;
    }

    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(messageProvider.getMessage("web.checkout.mail.from", null, null, null));
    message.setSentDate(new Date());
    message.setTo(loggedCustomer.getEmail());
    message.setSubject(messageProvider.getMessage("web.checkout.mail.object",
            new Object[] { order.getOrderId() }, null, null));
    message.setText(result);
    mailSender.send(message);
    return Action.SUCCESS;
}