Class MimeMessageItemWriter
- java.lang.Object
- org.springframework.batch.item.mail.javamail.MimeMessageItemWriter
- All Implemented Interfaces:
ItemWriter<javax.mail.internet.MimeMessage>
public class MimeMessageItemWriter extends java.lang.Object implements ItemWriter<javax.mail.internet.MimeMessage>
A simple
ItemWriterthat 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 methodJavaMailSender.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 specialJavaMailSenderthat caches connections to the server in between calls.Stateless, so automatically restartable.
- Since:
- 2.1
- Author:
- Dave Syer
Constructor Summary
Constructors Constructor Description MimeMessageItemWriter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Check mandatory properties (mailSender).voidsetJavaMailSender(org.springframework.mail.javamail.JavaMailSender mailSender)AJavaMailSenderto be used to send messages inwrite(List).voidsetMailErrorHandler(MailErrorHandler mailErrorHandler)The handler for failed messages.voidwrite(java.util.List<? extends javax.mail.internet.MimeMessage> items)Process the supplied data element.
Method Detail
setJavaMailSender
public void setJavaMailSender(org.springframework.mail.javamail.JavaMailSender mailSender)
AJavaMailSenderto be used to send messages inwrite(List).- Parameters:
mailSender- service for doing the work of sending a MIME message
setMailErrorHandler
public void setMailErrorHandler(MailErrorHandler mailErrorHandler)
The handler for failed messages. Defaults to aDefaultMailErrorHandler.- Parameters:
mailErrorHandler- the mail error handler to set
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.IllegalStateExceptionCheck mandatory properties (mailSender).- Throws:
java.lang.IllegalStateException- if the mandatory properties are not set- See Also:
InitializingBean.afterPropertiesSet()
write
public void write(java.util.List<? extends javax.mail.internet.MimeMessage> items) throws org.springframework.mail.MailExceptionDescription copied from interface:ItemWriterProcess the supplied data element. Will not be called with any null items in normal operation.- Specified by:
writein interfaceItemWriter<javax.mail.internet.MimeMessage>- Parameters:
items- the items to send- Throws:
org.springframework.mail.MailException- See Also:
ItemWriter.write(List)