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:net.maritimecloud.identityregistry.utils.EmailUtil.java

public void sendUserCreatedEmail(String sendTo, String userName, String loginName, String loginPassword)
        throws MailException {
    if (sendTo == null || sendTo.trim().isEmpty()) {
        throw new IllegalArgumentException("No email address!");
    }//  w  ww . jav a  2s .c om
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(sendTo);
    msg.setFrom(from);
    msg.setSubject(createdUserSubject);
    msg.setText(String.format(createdUserText, userName, loginName, loginPassword, portalUrl, projectIDPName));
    this.mailSender.send(msg);
}

From source file:br.com.mv.modulo.utils.ModuloEmailSender.java

public void sendEmail(String content) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setTo("suporte@mv.com.br");
    mailMessage.setFrom("dispensacao@mv.com.br");
    mailMessage.setSubject("Erro no sistema Dispensao de medicamento!");
    mailMessage.setText(content);/*w ww  .  j  a  v a 2 s  .c  o m*/

    try {
        mailSender.send(mailMessage);
    } catch (MailException ex) {
        LOGGER.error("Erro ao enviar email:", ex);
    }
}

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

/**
 * Perform the Account to MailMessage transformation.
 *//* ww  w . jav a2  s .c o 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:csns.util.NotificationService.java

public void notifiy(Subscribable subscribable, String subject, String vTemplate, Map<String, Object> vModels,
        boolean notificationFlag) {
    vModels.put("appUrl", appUrl);
    vModels.put("appEmail", appEmail);

    User user = userDao.getUser(SecurityUtils.getUser().getId());
    List<Subscription> subscriptions = subscriptionDao.getSubscriptions(subscribable);
    List<String> addresses = new ArrayList<String>();
    for (Subscription subscription : subscriptions)
        if (!subscription.isNotificationSent() && subscription.getSubscriber() != user) {
            addresses.add(subscription.getSubscriber().getEmail());
            if (subscription.isNotificationSent() != notificationFlag) {
                subscription.setNotificationSent(notificationFlag);
                subscriptionDao.saveSubscription(subscription);
            }//from  ww w .java 2  s  .c om
        }

    if (addresses.size() > 0) {
        String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, vTemplate, appEncoding,
                vModels);
        SimpleMailMessage email = new SimpleMailMessage();
        email.setFrom(appEmail);
        email.setTo(appEmail);
        email.setSubject(subject);
        email.setText(text);
        massMailSender.send(email, addresses);
    }
}

From source file:csns.util.EmailUtils.java

public boolean sendTextMail(Email email) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setSubject(email.getSubject());
    message.setText(getText(email));//from  w  ww. j av a2s  . c  o m
    message.setFrom(email.getAuthor().getPrimaryEmail());
    message.setCc(email.getAuthor().getPrimaryEmail());
    String addresses[] = getAddresses(email.getRecipients(), email.isUseSecondaryEmail())
            .toArray(new String[0]);
    if (addresses.length > 1) {
        message.setTo(appEmail);
        message.setBcc(addresses);
    } else
        message.setTo(addresses);

    mailSender.send(message);

    logger.info(email.getAuthor().getUsername() + " sent email to "
            + StringUtils.arrayToCommaDelimitedString(addresses));

    return true;
}

From source file:org.shredzone.cilla.service.notification.NotificationServiceImpl.java

/**
 * Send a {@link Notification} to a single {@link NotificationTarget}.
 * <p>/*from  ww  w . j a va2 s.  c o m*/
 * For the receiver's locale, the appropriate template is opened, it's placeholders
 * filled with the notification parameters, and the message sent to the target's
 * mail address.
 *
 * @param target
 *            {@link NotificationTarget} to send to
 * @param notification
 *            {@link Notification} to send
 */
private void sendToTarget(NotificationTarget target, Notification notification) throws CillaServiceException {
    try {
        Template template = freemarkerConfiguration.getTemplate(notification.getType() + ".ftl",
                target.getLocale());

        StringWriter out = new StringWriter();
        Environment env = template.createProcessingEnvironment(notification.getAttributes(), out, null);
        env.process();
        out.close();

        TemplateModel subjectTm = env.getVariable("subject");

        SimpleMailMessage msg = new SimpleMailMessage();
        msg.setFrom(sender);
        msg.setTo(target.getMail());
        msg.setSubject(subjectTm != null ? subjectTm.toString() : "");
        msg.setText(out.toString());
        mailSender.send(msg);

    } catch (IOException | TemplateException ex) {
        log.error("Failed to process template ", ex);
        throw new CillaServiceException("Could not process template", ex);
    }
}

From source file:org.taverna.server.master.notification.EmailDispatcher.java

@Override
public void dispatch(String messageSubject, String messageContent, String to) throws Exception {
    // Simple checks for acceptability
    if (!to.matches(".+@.+")) {
        log.info("did not send email notification: improper email address \"" + to + "\"");
        return;//from   w  w w  .j av a 2s. c  o m
    }

    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to.trim());
    message.setSubject(messageSubject);
    message.setText(messageContent);
    sender.send(message);
}

From source file:com.mycompany.spring.batch.mail.demo.batch.SampleBatchApplication.java

@Bean
public ItemProcessor processor() {
    ItemProcessor processor = new ItemProcessor() {

        @Override/*from   w w  w  .  j a va 2  s  .  c  o  m*/
        public SimpleMailMessage process(Object item) throws Exception {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom("root@localhost.localdomain");
            message.setTo("c7@localhost.localdomain");
            message.setSubject(item.toString());
            message.setSentDate(new Date());
            message.setText("Hello " + item.toString());
            System.out.println("Sending message with subject: " + item);
            return message;
        }
    };
    return processor;
}

From source file:uk.org.funcube.fcdw.config.MailConfig.java

@Bean
SimpleMailMessage alertMailMessage() {//from  ww w.j ava  2  s.c  o  m
    SimpleMailMessage alertMailMessage = new SimpleMailMessage();

    alertMailMessage.setFrom("dave@g4dpz.me.uk");
    alertMailMessage.setTo("dave@g4dpz.me.uk");
    alertMailMessage.setSubject("Alert - Exception occurred. Please investigate");

    return alertMailMessage;
}

From source file:ca.uoguelph.ccs.portal.services.feedback.dao.SimpleFeedbackMessageFormatterImpl.java

public SimpleMailMessage format(Feedback feedback) {

    SimpleMailMessage message = new SimpleMailMessage();

    message.setTo(targetEmail);/*from   w ww  .  j  ava  2  s .c o  m*/
    message.setFrom(fromAddress);

    message.setSubject("[Feedback] " + feedback.getSubject());

    StringBuffer details = new StringBuffer();
    details.append("NAME: ");
    details.append(null == feedback.getName() ? "<empty>" : feedback.getName());
    details.append("\n");
    details.append("\n");

    details.append("EMAIL: ");
    details.append(null == feedback.getEmailAddress() ? "<empty>" : feedback.getEmailAddress());
    details.append("\n");
    details.append("\n");

    details.append("DETAILS: ");
    details.append(feedback.getDetails());

    message.setText(details.toString());

    return message;
}