Extended
org.springframework.mail.MailSender interface for JavaMail,
supporting MIME messages both as direct arguments and through preparation
callbacks. Typically used in conjunction with the
MimeMessageHelper class for convenient creation of JavaMail
MimeMessage MimeMessages ,
including attachments etc.
Clients should talk to the mail sender through this interface if they need
mail functionality beyond
org.springframework.mail.SimpleMailMessage .
The production implementation is
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
MimeMessagePreparator mechanism, possibly using a
MimeMessageHelper for populating the message.
See
MimeMessageHelper MimeMessageHelper's javadoc for an example.
The entire JavaMail
javax.mail.Session management is abstracted
by 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
org.springframework.mail.MailSender client, but still straightforward
compared to traditional JavaMail code: Just let
JavaMailSender.createMimeMessage() return a plain
MimeMessage created with a
Session.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 Also: javax.mail.internet.MimeMessage See Also: javax.mail.Session See Also: JavaMailSenderImpl See Also: MimeMessagePreparator See Also: MimeMessageHelper |