Example usage for org.springframework.mail SimpleMailMessage setFrom

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

Introduction

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

Prototype

@Override
    public void setFrom(String from) 

Source Link

Usage

From source file:org.devgateway.ocds.web.spring.SendEmailService.java

public void sendEmail(final String subject, final String text, final String to) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(to);//from   w  w w. ja  va 2 s. c o  m
    msg.setFrom("support@developmentgateway.org");
    msg.setSubject(subject);
    msg.setText(text);
    try {
        LOGGER.info("Sending email " + msg);
        javaMailSenderImpl.send(msg);
    } catch (MailException e) {
        e.printStackTrace();
    }

}

From source file:org.homiefund.test.config.IntegrationConfiguration.java

@Bean(name = "templateMessage")
public SimpleMailMessage simpleMailMessage() {
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setFrom("demo@localhost");
    simpleMailMessage.setSubject("Invitiation to homiefund");

    return simpleMailMessage;
}

From source file:org.darwinathome.server.email.EmailSender.java

public void sendEmail(String toEmail, String fromEmail, String subject, Map<String, Object> model)
        throws IOException, TemplateException {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setSubject(subject);//from   w  ww. j a  va 2 s  .c  om
    message.setFrom(fromEmail);
    message.setTo(toEmail);
    String emailText = createEmailText(model);
    message.setText(emailText);
    mailSender.send(message);
}

From source file:org.khmeracademy.btb.auc.pojo.utilities.Notification_service.java

public void sendNotification(ArrayList<Winner> winner) throws MailException {

    for (int i = 0; i < winner.size(); i++) {
        SimpleMailMessage mail = new SimpleMailMessage();

        mail.setTo(winner.get(i).getCus_email());
        mail.setFrom("kuylim.auction@gmail.com");
        mail.setSubject("Win Auction");
        mail.setText("Dear,\n\n" + winner.get(i).getCus_firstname() + "\n" + "\tCongratulation! You have win an"
                + winner.get(i).getPro_name() + ". Your auction code is : " + winner.get(i).getAuc_id() + "\n"
                + "Please come to check out your product at our office.\n\n" + "Regard,\n\n" + "Auction Team.");

        javaMailSender.send(mail);/*  www .j  av a  2 s .  co m*/
    }
}

From source file:com.miserablemind.butter.domain.service.email.EmailService.java

/**
 * Sends a plain text message. Uses {@link EmailMessage#getPlainTextBody()}
 *
 * @param emailMessage prepared message object to be sent. Usually prepared by {@link EmailManager}
 *//*from w  w  w.  j  a  va  2s.c  om*/
public void sendTextMail(EmailMessage emailMessage) {

    SimpleMailMessage textMessage = new SimpleMailMessage();

    textMessage.setFrom(emailMessage.getFromAddress().getAddress());
    textMessage.setTo(emailMessage.getToEmail());
    textMessage.setSubject(emailMessage.getSubject());
    textMessage.setText(emailMessage.getPlainTextBody());

    try {
        this.mailSender.send(textMessage);
    } catch (MailException e) {
        logger.error("Email Service Exception Send Text Mail: " + e.getMessage(), e);
    }
}

From source file:org.devgateway.toolkit.forms.service.SendEmailService.java

/**
 * Send a reset password email. This is UNSAFE because passwords are sent in clear text.
 * Nevertheless some customers will ask for these emails to be sent, so ...
 * @param person/*from   w  ww  . jav a  2s .com*/
 * @param newPassword
 */
public void sendEmailResetPassword(final Person person, final String newPassword) {

    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(person.getEmail());
    msg.setFrom("support@developmentgateway.org");
    msg.setSubject("Recover your password");
    msg.setText("Dear " + person.getFirstName() + " " + person.getLastName() + ",\n\n"
            + "These are your new login credentials for E-Procurement Toolkit.\n\n" + "Username: "
            + person.getUsername() + "\n" + "Password: " + newPassword + "\n\n"
            + "At login, you will be prompted to change your password to one of your choice.\n\n"
            + "Thank you,\n" + "DG Team");
    try {
        javaMailSenderImpl.send(msg);
    } catch (MailException e) {
        e.printStackTrace();
    }

}

From source file:com.springsource.greenhouse.invite.mail.AsyncMailInviteService.java

private SimpleMailMessage createInviteMailMessage(Invitee to, String text) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setFrom("Greenhouse <noreply@springsource.com>");
    mailMessage.setTo(to.getEmail());/*from  w  w  w.j  av  a 2  s  .c  o m*/
    mailMessage.setSubject("Your Greenhouse Invitation");
    mailMessage.setText(text);
    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   w  w w  . j a v a2s  . c o m*/
        }

    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:org.shredzone.cilla.service.notification.NotificationServiceImpl.java

/**
 * Send a {@link Notification} to a single {@link NotificationTarget}.
 * <p>//w ww  .java  2  s . c  om
 * 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: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);//from w  ww .j a va  2s  .c  o  m

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