Example usage for org.springframework.mail SimpleMailMessage setTo

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

Introduction

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

Prototype

@Override
    public void setTo(String... to) 

Source Link

Usage

From source file:ubc.pavlab.aspiredb.server.controller.BaseController.java

/**
 * @param name/*  w  w w.j a va2s  .c  o m*/
 * @param subject
 * @param emailAddress
 * @param templateName
 * @param model
 */
protected void sendEmail(String name, String emailAddress, String subject, String templateName,
        Map<String, Object> model) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setFrom(ConfigUtils.getAdminEmailAddress());
    mailMessage.setSubject(subject);
    mailMessage.setTo(name + "<" + emailAddress + ">");
    mailEngine.sendMessage(mailMessage, templateName, model);
}

From source file:ubc.pavlab.aspiredb.server.service.ProjectServiceImpl.java

private void sendEmail(String username, String email, Map<String, Object> model) {
    String subject = this.messageUtil.getText("projectUpload.email.subject", Locale.getDefault());
    String templateName = "projectUploaded.vm";

    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setFrom(ConfigUtils.getAdminEmailAddress());
    mailMessage.setSubject(subject);//from  ww w  .  j  a va 2s . c  om
    mailMessage.setTo(username + "<" + email + ">");
    mailEngine.sendMessage(mailMessage, templateName, model);
}

From source file:ubc.pavlab.aspiredb.server.util.MailEngineImpl.java

/**
 * Sends a message to the gemma administrator as defined in the Gemma.properties file
 * /*ww  w  .j  a  v a2 s.  co  m*/
 * @param bodyText
 * @param subject
 */
@Override
public void sendAdminMessage(String bodyText, String subject) {

    if ((bodyText == null) && (subject == null)) {
        log.warn("Not sending empty email, both subject and body are null");
        return;
    }

    log.info("Sending email notification to administrator regarding: " + subject);
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(ConfigUtils.getAdminEmailAddress());
    msg.setFrom(ConfigUtils.getAdminEmailAddress());
    msg.setSubject(subject);
    msg.setText(bodyText);
    this.send(msg);
}

From source file:ubic.gemma.core.util.MailUtilsImpl.java

@Override
public void sendTaskCompletedNotificationEmail(EmailNotificationContext emailNotificationContext,
        TaskResult taskResult) {// w ww . j  a v  a 2s .  co m
    String taskId = emailNotificationContext.getTaskId();
    String submitter = emailNotificationContext.getSubmitter();
    String taskName = emailNotificationContext.getTaskName();

    if (StringUtils.isNotBlank(submitter)) {
        User user = userService.findByUserName(submitter);

        assert user != null;

        String emailAddress = user.getEmail();

        if (emailAddress != null) {
            MailUtilsImpl.log.info("Sending email notification to " + emailAddress);
            SimpleMailMessage msg = new SimpleMailMessage();
            msg.setTo(emailAddress);
            msg.setFrom(Settings.getAdminEmailAddress());
            msg.setSubject("Gemma task completed");

            String logs = "";
            if (taskResult.getException() != null) {
                logs += "Task failed with :\n";
                logs += taskResult.getException().getMessage();
            }

            msg.setText("A job you started on Gemma is completed (taskId=" + taskId + ", " + taskName + ")\n\n"
                    + logs + "\n");

            mailEngine.send(msg);
        }
    }
}

From source file:ubic.gemma.persistence.service.TableMaintenanceUtilImpl.java

private void sendEmail(Gene2CsStatus results) {
    if (!sendEmail)
        return;/*from   w  ww .j  a  va  2s.c o m*/
    SimpleMailMessage msg = new SimpleMailMessage();
    String adminEmailAddress = Settings.getAdminEmailAddress();
    if (StringUtils.isBlank(adminEmailAddress)) {
        TableMaintenanceUtilImpl.log.warn(
                "No administrator email address could be found, so gene2cs status email will not be sent.");
        return;
    }
    msg.setTo(adminEmailAddress);
    msg.setSubject("Gene2Cs update status.");
    msg.setText("Gene2Cs updating was run.\n" + results.getAnnotation());
    mailEngine.send(msg);
    TableMaintenanceUtilImpl.log.info("Email notification sent to " + adminEmailAddress);
}

From source file:ubic.gemma.persistence.util.MailEngineImpl.java

/**
 * Sends a message to the gemma administrator as defined in the Gemma.properties file
 *//*from ww  w .  j a  v a  2s  .  c  om*/
@Override
public void sendAdminMessage(String bodyText, String subject) {

    if ((bodyText == null) && (subject == null)) {
        MailEngineImpl.log.warn("Not sending empty email, both subject and body are null");
        return;
    }

    MailEngineImpl.log.info("Sending email notification to administrator regarding: " + subject);
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(Settings.getAdminEmailAddress());
    msg.setFrom(Settings.getAdminEmailAddress());
    msg.setSubject(subject);
    msg.setText(bodyText);
    this.send(msg);
}

From source file:ubic.gemma.util.MailUtilsImpl.java

@Override
public void sendTaskCompletedNotificationEmail(EmailNotificationContext emailNotificationContext,
        TaskResult taskResult) {/*from  ww  w.j  a va  2s .  c o  m*/
    String taskId = emailNotificationContext.getTaskId();
    String submitter = emailNotificationContext.getSubmitter();
    String taskName = emailNotificationContext.getTaskName();

    if (StringUtils.isNotBlank(submitter)) {
        User user = userService.findByUserName(submitter);

        assert user != null;

        String emailAddress = user.getEmail();

        if (emailAddress != null) {
            log.debug("Sending email notification to " + emailAddress);
            SimpleMailMessage msg = new SimpleMailMessage();
            msg.setTo(emailAddress);
            msg.setFrom(ConfigUtils.getAdminEmailAddress());
            msg.setSubject("Gemma task completed");

            String logs = "";
            if (taskResult.getException() != null) {
                logs += "Task failed with :\n";
                logs += taskResult.getException().getMessage();
            }

            msg.setText("A job you started on Gemma is completed (taskid=" + taskId + ", " + taskName + ")\n\n"
                    + logs + "\n");

            /*
             * TODO provide a link to something relevant something like:
             */
            // String url = ConfigUtils.getBaseUrl() + "user/tasks.html?taskId=" + taskId;

            mailEngine.send(msg);
        }
    }
}

From source file:ubic.gemma.web.controller.BaseController.java

protected void sendConfirmationEmail(HttpServletRequest request, String token, String username, String email,
        Map<String, Object> model, String templateName) {
    try {//from w w  w  . j a  v a  2s.  com
        model.put("username", username);
        model.put("confirmLink",
                Settings.getBaseUrl() + "confirmRegistration.html?key=" + token + "&username=" + username);

        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(Settings.getAdminEmailAddress());
        mailMessage.setSubject(getText("signup.email.subject", request.getLocale()));
        mailMessage.setTo(username + "<" + email + ">");
        mailEngine.sendMessage(mailMessage, templateName, model);

    } catch (Exception e) {
        log.error("Couldn't send email to " + email, e);
    }
}

From source file:ubic.gemma.web.controller.BaseFormController.java

/**
 * Convenience message to send messages to users
 *///from  w w w .  j  a v  a2s. co  m
protected void sendEmail(User user, String msg) {
    if (StringUtils.isBlank(user.getEmail())) {
        log.warn("Could not send email to " + user + ", no email address");
    }
    log.debug("sending e-mail to user [" + user.getEmail() + "]...");
    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo(user.getFullName() + "<" + user.getEmail() + ">");

    mailEngine.send(message);
}

From source file:ubic.gemma.web.controller.BaseFormController.java

/**
 * Convenience message to send messages to users
 *///from w  w  w.  j  a  va 2s  .c o  m
protected void sendEmail(User user, String templateName, Map<String, Object> model) {
    if (StringUtils.isBlank(user.getEmail())) {
        log.warn("Could not send email to " + user + ", no email address");
    }
    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo(user.getFullName() + "<" + user.getEmail() + ">");
    mailEngine.sendMessage(message, templateName, model);
}