public class MimeMessageItemWriter extends Object implements ItemWriter<javax.mail.internet.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.
Constructor and Description |
---|
MimeMessageItemWriter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Check mandatory properties (mailSender).
|
void |
setJavaMailSender(org.springframework.mail.javamail.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 javax.mail.internet.MimeMessage> items)
Process the supplied data element.
|
public void setJavaMailSender(org.springframework.mail.javamail.JavaMailSender mailSender)
JavaMailSender
to be used to send messages in write(List)
.mailSender
- public void setMailErrorHandler(MailErrorHandler mailErrorHandler)
DefaultMailErrorHandler
.mailErrorHandler
- the mail error handler to setpublic void afterPropertiesSet() throws IllegalStateException
IllegalStateException
- if the mandatory properties are not setInitializingBean.afterPropertiesSet()
public void write(List<? extends javax.mail.internet.MimeMessage> items) throws org.springframework.mail.MailException
ItemWriter
write
in interface ItemWriter<javax.mail.internet.MimeMessage>
items
- the items to sendorg.springframework.mail.MailException
ItemWriter.write(List)
Copyright © 2014 Pivotal. All rights reserved.