Example usage for org.springframework.mail MailSender send

List of usage examples for org.springframework.mail MailSender send

Introduction

In this page you can find the example usage for org.springframework.mail MailSender send.

Prototype

void send(SimpleMailMessage... simpleMessages) throws MailException;

Source Link

Document

Send the given array of simple mail messages in batch.

Usage

From source file:ar.com.zauber.commons.spring.mail.ProxyMailSender.java

/** @see MailSender#send(SimpleMailMessage)  */
public final void send(final SimpleMailMessage msg) throws MailException {
    for (final MailSender sender : senders) {
        sender.send(msg);
    }/*from   w ww .  j a  va2 s  .c o  m*/
}

From source file:ar.com.zauber.commons.spring.mail.ProxyMailSender.java

/** @see MailSender#send(SimpleMailMessage[]) */
public final void send(final SimpleMailMessage[] msgs) throws MailException {
    for (final MailSender sender : senders) {
        sender.send(msgs);
    }/*from   w w  w.  ja v  a2  s  .c  o m*/
}

From source file:com.bbytes.zorba.job.SendMailJob.java

public void sendMail(String from, String to, String subject, String body, MailSender mailSender) {

    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);/*from w  w  w .  ja v a2 s  .c o  m*/
    message.setTo(to);
    message.setSubject(subject);
    message.setText(body);
    mailSender.send(message);

}

From source file:ar.com.zauber.commons.message.impl.mail.MimeEmailNotificationStrategy.java

/** @see NotificationStrategy#execute(NotificationAddress[], Message) */
public final void execute(final NotificationAddress[] addresses, final Message message) {
    try {/*www .j a  v  a2s . c  o  m*/
        final MailSender mailSender = getMailSender();
        //This is ugly....but if it is not a JavaMailSender it will
        //fail (for instance during tests). And the only way to
        //create a Multipartemail is through JavaMailSender
        if (mailSender instanceof JavaMailSender) {
            final JavaMailSender javaMailSender = (JavaMailSender) mailSender;
            final MimeMessage mail = javaMailSender.createMimeMessage();
            final MimeMessageHelper helper = new MimeMessageHelper(mail, true);
            helper.setFrom(getFromAddress().getEmailStr());
            helper.setTo(SimpleEmailNotificationStrategy.getEmailAddresses(addresses));
            helper.setReplyTo(getEmailAddress(message.getReplyToAddress()));
            helper.setSubject(message.getSubject());
            setContent(helper, (MultipartMessage) message);
            addHeaders(message, mail);
            javaMailSender.send(mail);
        } else {
            final SimpleMailMessage mail = new SimpleMailMessage();
            mail.setFrom(getFromAddress().getEmailStr());
            mail.setTo(getEmailAddresses(addresses));
            mail.setReplyTo(getEmailAddress(message.getReplyToAddress()));
            mail.setSubject(message.getSubject());
            mail.setText(message.getContent());
            mailSender.send(mail);
        }
    } catch (final MessagingException e) {
        throw new RuntimeException("Could not send message", e);
    } catch (final UnsupportedEncodingException e) {
        throw new RuntimeException("Could not send message", e);
    }

}