Extended {@link org.springframework.mail.MailSender} interface for JavaMail,supporting MIME messages both as direct arguments and through preparation callbacks. Typically used in conjunction with the {@link MimeMessageHelper}class for convenient creation of JavaMail {@link MimeMessage MimeMessages}, including attachments etc.
Clients should talk to the mail sender through this interface if they need mail functionality beyond {@link org.springframework.mail.SimpleMailMessage}. The production implementation is {@link JavaMailSenderImpl}; for testing, mocks can be created based on this interface. Clients will typically receive the JavaMailSender reference through dependency injection.
The recommended way of using this interface is the {@link MimeMessagePreparator}mechanism, possibly using a {@link MimeMessageHelper} for populating the message.See {@link MimeMessageHelper MimeMessageHelper's javadoc} for an example.
The entire JavaMail {@link javax.mail.Session} management is abstractedby the JavaMailSender. Client code should not deal with a Session in any way, rather leave the entire JavaMail configuration and resource handling to the JavaMailSender implementation. This also increases testability.
A JavaMailSender client is not as easy to test as a plain {@link org.springframework.mail.MailSender} client, but still straightforwardcompared to traditional JavaMail code: Just let {@link #createMimeMessage()}return a plain {@link MimeMessage} created with aSession.getInstance(new Properties())
call, and check the passed-in messages in your mock implementations of the various send
methods.
@author Juergen Hoeller
@since 07.10.2003
@see javax.mail.internet.MimeMessage
@see javax.mail.Session
@see JavaMailSenderImpl
@see MimeMessagePreparator
@see MimeMessageHelper