Class MimeMessageItemWriter
- All Implemented Interfaces:
ItemWriter<jakarta.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.
- Since:
- 2.1
- Author:
- Dave Syer, Mahmoud Ben Hassine
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Check mandatory properties (mailSender).void
setJavaMailSender
(org.springframework.mail.javamail.JavaMailSender mailSender) AJavaMailSender
to be used to send messages inwrite(Chunk)
.void
setMailErrorHandler
(MailErrorHandler mailErrorHandler) The handler for failed messages.void
Process the supplied data element.
-
Constructor Details
-
MimeMessageItemWriter
public MimeMessageItemWriter()
-
-
Method Details
-
setJavaMailSender
public void setJavaMailSender(org.springframework.mail.javamail.JavaMailSender mailSender) AJavaMailSender
to be used to send messages inwrite(Chunk)
.- Parameters:
mailSender
- service for doing the work of sending a MIME message
-
setMailErrorHandler
The handler for failed messages. Defaults to aDefaultMailErrorHandler
.- Parameters:
mailErrorHandler
- the mail error handler to set
-
afterPropertiesSet
Check mandatory properties (mailSender).- Throws:
IllegalStateException
- if the mandatory properties are not set- See Also:
-
InitializingBean.afterPropertiesSet()
-
write
public void write(Chunk<? extends jakarta.mail.internet.MimeMessage> chunk) throws org.springframework.mail.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 interfaceItemWriter<jakarta.mail.internet.MimeMessage>
- Parameters:
chunk
- the chunk of items to send- Throws:
org.springframework.mail.MailException
- See Also:
-