java.lang.Object | |
↳ | org.springframework.mail.javamail.JavaMailSenderImpl |
Production implementation of the JavaMailSender
interface,
supporting both JavaMail MimeMessage MimeMessages and Spring
SimpleMailMessages
. Can also be used as a
plain MailSender
implementation.
Allows for defining all settings locally as bean properties. Alternatively, a pre-configured JavaMail javax.mail.Session can be specified, possibly pulled from an application server's JNDI environment.
Non-default properties in this object will always override the settings
in the JavaMail Session
. Note that if overriding all values locally,
there is no added value in setting a pre-configured Session
.
setSession(Session)
setJavaMailProperties(Properties)
setHost(String)
setPort(int)
setUsername(String)
setPassword(String)
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DEFAULT_PORT | The default port: -1 | |||||||||
String | DEFAULT_PROTOCOL | The default protocol: 'smtp' |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new instance of the
JavaMailSenderImpl class. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new JavaMail MimeMessage for the underlying JavaMail Session
of this sender, using the given input stream as the message source.
| |||||||||||
This implementation creates a SmartMimeMessage, holding the specified
default encoding and default FileTypeMap.
| |||||||||||
Return the default encoding for MimeMessage MimeMessages,
or
null if none. | |||||||||||
Return the default Java Activation FileTypeMap for
MimeMessage MimeMessages, or
null if none. | |||||||||||
Return the mail server host.
| |||||||||||
Allow Map access to the JavaMail properties of this sender,
with the option to add or override specific entries.
| |||||||||||
Return the password for the account at the mail host.
| |||||||||||
Return the mail server port.
| |||||||||||
Return the mail protocol.
| |||||||||||
Return the JavaMail
Session ,
lazily initializing it if hasn't been specified explicitly. | |||||||||||
Return the username for the account at the mail host.
| |||||||||||
Send the given JavaMail MIME message.
| |||||||||||
Send the given array of simple mail messages in batch.
| |||||||||||
Send the given simple mail message.
| |||||||||||
Send the given array of JavaMail MIME messages in batch.
| |||||||||||
Set the default encoding to use for MimeMessage MimeMessages
created by this instance.
| |||||||||||
Set the default Java Activation FileTypeMap to use for
MimeMessage MimeMessages created by this instance.
| |||||||||||
Set the mail server host, typically an SMTP host.
| |||||||||||
Set JavaMail properties for the
Session . | |||||||||||
Set the password for the account at the mail host, if any.
| |||||||||||
Set the mail server port.
| |||||||||||
Set the mail protocol.
| |||||||||||
Set the JavaMail
Session , possibly pulled from JNDI. | |||||||||||
Set the username for the account at the mail host, if any.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Actually send the given array of MimeMessages via JavaMail.
| |||||||||||
Obtain a Transport object from the given JavaMail Session,
using the configured protocol.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.mail.MailSender
| |||||||||||
From interface
org.springframework.mail.javamail.JavaMailSender
|
The default port: -1
Create a new instance of the JavaMailSenderImpl
class.
Initializes the "defaultFileTypeMap"
property with a default ConfigurableMimeFileTypeMap
.
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 |
---|
MailException |
---|
This implementation creates a SmartMimeMessage, holding the specified
default encoding and default FileTypeMap. This special defaults-carrying
message will be autodetected by MimeMessageHelper
, which will use
the carried encoding and FileTypeMap unless explicitly overridden.
Return the default encoding for MimeMessage MimeMessages,
or null
if none.
Return the default Java Activation FileTypeMap for
MimeMessage MimeMessages, or null
if none.
Allow Map access to the JavaMail properties of this sender, with the option to add or override specific entries.
Useful for specifying entries directly, for example via "javaMailProperties[mail.smtp.auth]".
Return the mail server port.
Return the JavaMail Session
,
lazily initializing it if hasn't been specified explicitly.
Send the given JavaMail MIME message.
The message needs to have been created with createMimeMessage()
.
mimeMessage | message to send |
---|
MailException |
---|
Send the given array of simple mail messages in batch.
simpleMessages | the messages to send |
---|
MailException |
---|
Send the given simple mail message.
simpleMessage | the message to send |
---|
MailException |
---|
Send the given array of JavaMail MIME messages in batch.
The messages need to have been created with createMimeMessage()
.
mimeMessages | messages to send |
---|
MailException |
---|
Set the default encoding to use for MimeMessage MimeMessages created by this instance.
Such an encoding will be auto-detected by MimeMessageHelper
.
Set the default Java Activation FileTypeMap to use for MimeMessage MimeMessages created by this instance.
A FileTypeMap
specified here will be autodetected by
MimeMessageHelper
, avoiding the need to specify the
FileTypeMap
for each MimeMessageHelper
instance.
For example, you can specify a custom instance of Spring's
ConfigurableMimeFileTypeMap
here. If not explicitly specified,
a default ConfigurableMimeFileTypeMap
will be used, containing
an extended set of MIME type mappings (as defined by the
mime.types
file contained in the Spring jar).
Set the mail server host, typically an SMTP host.
Default is the default host of the underlying JavaMail Session.
Set JavaMail properties for the Session
.
A new Session
will be created with those properties.
Use either this method or setSession(Session)
, but not both.
Non-default properties in this instance will override given JavaMail properties.
Set the password for the account at the mail host, if any.
Note that the underlying JavaMail Session
has to be
configured with the property "mail.smtp.auth"
set to
true
, else the specified password will not be sent to the
mail server by the JavaMail runtime. If you are not explicitly passing
in a Session
to use, simply specify this setting via
setJavaMailProperties(Properties)
.
Set the mail server port.
Default is DEFAULT_PORT
, letting JavaMail use the default
SMTP port (25).
Set the JavaMail Session
, possibly pulled from JNDI.
Default is a new Session
without defaults, that is
completely configured via this instance's properties.
If using a pre-configured Session
, non-default properties
in this instance will override the settings in the Session
.
Set the username for the account at the mail host, if any.
Note that the underlying JavaMail Session
has to be
configured with the property "mail.smtp.auth"
set to
true
, else the specified username will not be sent to the
mail server by the JavaMail runtime. If you are not explicitly passing
in a Session
to use, simply specify this setting via
setJavaMailProperties(Properties)
.
Actually send the given array of MimeMessages via JavaMail.
mimeMessages | MimeMessage objects to send |
---|---|
originalMessages | corresponding original message objects that the MimeMessages have been created from (with same array length and indices as the "mimeMessages" array), if any |
MailAuthenticationException | in case of authentication failure |
---|---|
MailSendException | in case of failure when sending a message |
MailException |
Obtain a Transport object from the given JavaMail Session, using the configured protocol.
Can be overridden in subclasses, e.g. to return a mock Transport object.
NoSuchProviderException |
---|
getProtocol()