org.springframework.mail.javamail.JavaMailSender |
Known Indirect Subclasses |
Extended 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 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'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
MailSender
client, but still straightforward
compared to traditional JavaMail code: Just let 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.
JavaMailSenderImpl
MimeMessagePreparator
MimeMessageHelper
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new JavaMail MimeMessage for the underlying JavaMail Session
of this sender, using the given input stream as the message source.
| |||||||||||
Create a new JavaMail MimeMessage for the underlying JavaMail Session
of this sender.
| |||||||||||
Send the given array of JavaMail MIME messages in batch.
| |||||||||||
Send the given JavaMail MIME message.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.springframework.mail.MailSender
|
Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender, using the given input stream as the message source.
contentStream | the raw MIME input stream for the message |
---|
MailParseException | in case of message creation failure |
---|---|
MailException |
Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender. Needs to be called to create MimeMessage instances that can be prepared by the client and passed to send(MimeMessage).
Send the given array of JavaMail MIME messages in batch.
The messages need to have been created with createMimeMessage()
.
mimeMessages | messages to send |
---|
MailAuthenticationException | in case of authentication failure |
---|---|
MailSendException | in case of failure when sending a message |
MailException |
Send the given JavaMail MIME message.
The message needs to have been created with createMimeMessage()
.
mimeMessage | message to send |
---|
MailAuthenticationException | in case of authentication failure |
---|---|
MailSendException | in case of failure when sending the message |
MailException |