Example usage for org.springframework.mail SimpleMailMessage setSubject

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

Introduction

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

Prototype

@Override
    public void setSubject(String subject) 

Source Link

Usage

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  2  s. c  o m*/
        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.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");
    }//from  w  ww. ja  va  2 s  . c  o  m

    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);
    //        }// ww w.  j  ava 2  s. c  o  m
    //        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 www.  j  av  a 2 s.c o 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);/*from ww w  .j a  v a 2s.  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  .  ja  v  a2 s  .c om

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

    return stepExecution.getExitStatus();
}