org.springframework.batch.item.mail.javamail
Class MimeMessageItemWriter

java.lang.Object
  extended by org.springframework.batch.item.mail.javamail.MimeMessageItemWriter
All Implemented Interfaces:
ItemWriter<MimeMessage>

public class MimeMessageItemWriter
extends Object
implements ItemWriter<MimeMessage>

A simple ItemWriter that can send mail messages. If it fails there is no guarantee about which of the messages were sent, but the ones that failed can be picked up in the error handler. Because the mail protocol is not transactional, failures should be dealt with here if possible rather than allowing them to be rethrown (which is the default).

Delegates the actual sending of messages to a JavaMailSender, using the batch method JavaMailSender.send(MimeMessage[]), which normally uses a single server connection for the whole batch (depending on the implementation). The efficiency of for large volumes of messages (repeated calls to the item writer) might be improved by the use of a special JavaMailSender that caches connections to the server in between calls.

Stateless, so automatically restartable.

Since:
2.1
Author:
Dave Syer

Constructor Summary
MimeMessageItemWriter()
           
 
Method Summary
 void afterPropertiesSet()
          Check mandatory properties (mailSender).
 void setJavaMailSender(JavaMailSender mailSender)
          A JavaMailSender to be used to send messages in write(List).
 void setMailErrorHandler(MailErrorHandler mailErrorHandler)
          The handler for failed messages.
 void write(List<? extends MimeMessage> items)
          Process the supplied data element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeMessageItemWriter

public MimeMessageItemWriter()
Method Detail

setJavaMailSender

public void setJavaMailSender(JavaMailSender mailSender)
A JavaMailSender to be used to send messages in write(List).

Parameters:
mailSender -

setMailErrorHandler

public void setMailErrorHandler(MailErrorHandler mailErrorHandler)
The handler for failed messages. Defaults to a DefaultMailErrorHandler.

Parameters:
mailErrorHandler - the mail error handler to set

afterPropertiesSet

public void afterPropertiesSet()
                        throws IllegalStateException
Check mandatory properties (mailSender).

Throws:
IllegalStateException - if the mandatory properties are not set
See Also:
InitializingBean.afterPropertiesSet()

write

public void write(List<? extends MimeMessage> items)
           throws MailException
Description copied from interface: ItemWriter
Process the supplied data element. Will not be called with any null items in normal operation.

Specified by:
write in interface ItemWriter<MimeMessage>
Parameters:
items - the items to send
Throws:
MailException
See Also:
ItemWriter.write(List)


Copyright © 2013 SpringSource. All Rights Reserved.