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:ubic.gemma.util.MailUtilsImpl.java

@Override
public void sendTaskCompletedNotificationEmail(EmailNotificationContext emailNotificationContext,
        TaskResult taskResult) {//from   w w  w  .ja  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) {
            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.common.auditAndSecurity.SecurityControllerImpl.java

@Override
public boolean addUserToGroup(String userName, String groupName) {

    User userTakingAction = userManager.getCurrentUser();

    if (userTakingAction == null) {
        throw new IllegalStateException("Cannot add user to group when user is not logged in");
    }/* ww w.j ava2s  .  c om*/

    User u;
    if (userManager.userExists(userName)) {
        u = userManager.findByUserName(userName);
        if (!u.getEnabled()) {
            throw new IllegalArgumentException("Sorry, that user's account is not enabled.");
        }

        securityService.addUserToGroup(userName, groupName);
    } else if (userManager.userWithEmailExists(userName)) {
        u = userManager.findByEmail(userName);
        if (!u.getEnabled()) {
            throw new IllegalArgumentException("Sorry, that user's account is not enabled.");
        }

        String uname = u.getUserName();
        securityService.addUserToGroup(uname, groupName);
    } else {
        throw new IllegalArgumentException("Sorry, there is no matching user.");
    }

    /*
     * send the user an email.
     */
    String emailAddress = u.getEmail();
    if (StringUtils.isNotBlank(emailAddress)) {
        SecurityControllerImpl.log.debug("Sending email notification to " + emailAddress);
        SimpleMailMessage msg = new SimpleMailMessage();
        msg.setTo(emailAddress);
        msg.setFrom(Settings.getAdminEmailAddress());
        msg.setSubject("You have been added to a group on Gemma");

        msg.setText(userTakingAction.getUserName() + " has added you to the group '" + groupName
                + "'.\nTo view groups you belong to, visit " + SecurityControllerImpl.GROUP_MANAGER_URL
                + "\n\nIf you believe you received this email in error, contact "
                + Settings.getAdminEmailAddress() + ".");

        mailEngine.send(msg);
    }

    return true;
}

From source file:uk.ac.ebi.intact.dataexchange.dbimporter.listener.MailNotifierStepExecutionListener.java

public void beforeStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[IntAct_import] Started step: " + stepExecution.getStepName() + "");
    message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution());
    message.setTo(stepExecution.getJobParameters().getString("email.recipient"));

    //        try{
    //            mailSender.send(message);
    //        }/*from ww w.  ja  v a 2 s  . c om*/
    //        catch (MailException e){
    //            log.error("Impossible to send e-mail", e);
    //        }
}

From source file:uk.ac.ebi.intact.dataexchange.dbimporter.listener.MailNotifierStepExecutionListener.java

public ExitStatus afterStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[IntAct_import] Finished step: " + stepExecution.getStepName() + " Exit status: "
            + stepExecution.getExitStatus().getExitCode());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n"
            + stepExecution.getJobExecution());
    message.setTo(stepExecution.getJobParameters().getString("email.recipient"));

    //        try{
    //            mailSender.send(message);
    //        }//from w w w  .j a  v  a  2 s  . co m
    //        catch (MailException e){
    //            log.error("Impossible to send e-mail", e);
    //        }

    return stepExecution.getExitStatus();
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.exporter.listener.MailNotifierStepExecutionListener.java

public void beforeStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[IntAct_export] Started step: " + stepExecution.getStepName() + "");
    message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution());
    message.setTo(recipients);//ww w .  ja v a  2  s  .  c  o m

    try {
        mailSender.send(message);
    } catch (MailException e) {
        log.error("Impossible to send e-mail", e);
    }
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.exporter.listener.MailNotifierStepExecutionListener.java

public ExitStatus afterStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[IntAct_export] Finished step: " + stepExecution.getStepName() + " Exit status: "
            + stepExecution.getExitStatus().getExitCode());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n"
            + stepExecution.getJobExecution());
    message.setTo(recipients);/*from  w w  w.j  av  a 2  s. c  om*/

    try {
        mailSender.send(message);
    } catch (MailException e) {
        log.error("Impossible to send e-mail", e);
    }

    return stepExecution.getExitStatus();
}