Class SimpleMailMessageItemWriter
- All Implemented Interfaces:
ItemWriter<org.springframework.mail.SimpleMailMessage>,org.springframework.beans.factory.InitializingBean
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 MailSender, using the
batch method MailSender.send(SimpleMailMessage[]), 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
MailSender that caches connections to the server in between calls.
Stateless, so automatically restartable.
- Since:
- 2.1
- Author:
- Dave Syer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck mandatory properties (mailSender).voidsetMailErrorHandler(MailErrorHandler mailErrorHandler) The handler for failed messages.voidsetMailSender(org.springframework.mail.MailSender mailSender) AMailSenderto be used to send messages inwrite(List).voidProcess the supplied data element.
-
Constructor Details
-
SimpleMailMessageItemWriter
public SimpleMailMessageItemWriter()
-
-
Method Details
-
setMailSender
public void setMailSender(org.springframework.mail.MailSender mailSender) AMailSenderto be used to send messages inwrite(List).- Parameters:
mailSender- TheMailSenderto be used.
-
setMailErrorHandler
The handler for failed messages. Defaults to aDefaultMailErrorHandler.- Parameters:
mailErrorHandler- the mail error handler to set
-
afterPropertiesSet
Check mandatory properties (mailSender).- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
IllegalStateException- if the mandatory properties are not set- See Also:
-
InitializingBean.afterPropertiesSet()
-
write
public void write(List<? extends org.springframework.mail.SimpleMailMessage> items) throws org.springframework.mail.MailException Description copied from interface:ItemWriterProcess the supplied data element. Will not be called with any null items in normal operation.- Specified by:
writein interfaceItemWriter<org.springframework.mail.SimpleMailMessage>- Parameters:
items- the items to send- Throws:
org.springframework.mail.MailException- See Also:
-