class MimeMessageItemWriter implements ItemWriter<MimeMessage> {

	private JavaMailSender mailSender;

	private MailErrorHandler mailErrorHandler = new DefaultMailErrorHandler();

	/**
	 * A {@link JavaMailSender} to be used to send messages in {@link #write(Chunk)}.
	 * @param mailSender service for doing the work of sending a MIME message
	 */
	public void setJavaMailSender(JavaMailSender mailSender) {
		this.mailSender = mailSender;
	}

	/**
	 * The handler for failed messages. Defaults to a {@link DefaultMailErrorHandler}.
	 * @param mailErrorHandler the mail error handler to set
	 */
	public void setMailErrorHandler(MailErrorHandler mailErrorHandler) {
		this.mailErrorHandler = mailErrorHandler;
	}

	/**
	 * Check mandatory properties (mailSender).
	 * @throws IllegalStateException if the mandatory properties are not set
	 *
	 * @see InitializingBean#afterPropertiesSet()
	 */
	public void afterPropertiesSet() throws IllegalStateException {
		Assert.state(mailSender != null, "A MailSender must be provided.");
	}

	/**
	 * @param chunk the chunk of items to send
	 * @see ItemWriter#write(Chunk)
	 */
	@Override
	public void write(Chunk<? extends MimeMessage> chunk) throws MailException {<FILL_FUNCTION_BODY>}

}

		try {
			mailSender.send(chunk.getItems().toArray(new MimeMessage[chunk.size()]));
		}
		catch (MailSendException e) {
			Map<Object, Exception> failedMessages = e.getFailedMessages();
			for (Entry<Object, Exception> entry : failedMessages.entrySet()) {
				mailErrorHandler.handle(new MimeMailMessage((MimeMessage) entry.getKey()), entry.getValue());
			}
		}
	
<no_super_class>