public class JavaMailSenderImpl extends Object implements JavaMailSender
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_PORT
The default port: -1
|
static String |
DEFAULT_PROTOCOL
The default protocol: 'smtp'
|
| 构造器和说明 |
|---|
JavaMailSenderImpl()
Create a new instance of the
JavaMailSenderImpl class. |
| 限定符和类型 | 方法和说明 |
|---|---|
javax.mail.internet.MimeMessage |
createMimeMessage()
This implementation creates a SmartMimeMessage, holding the specified
default encoding and default FileTypeMap.
|
javax.mail.internet.MimeMessage |
createMimeMessage(InputStream contentStream)
Create a new JavaMail MimeMessage for the underlying JavaMail Session
of this sender, using the given input stream as the message source.
|
protected void |
doSend(javax.mail.internet.MimeMessage[] mimeMessages,
Object[] originalMessages)
Actually send the given array of MimeMessages via JavaMail.
|
String |
getDefaultEncoding() |
FileTypeMap |
getDefaultFileTypeMap() |
String |
getHost() |
Properties |
getJavaMailProperties()
Allow Map access to the JavaMail properties of this sender,
with the option to add or override specific entries.
|
String |
getPassword() |
int |
getPort() |
String |
getProtocol() |
javax.mail.Session |
getSession()
Return the JavaMail
Session,
lazily initializing it if hasn't been specified explicitly. |
protected javax.mail.Transport |
getTransport(javax.mail.Session session)
Obtain a Transport object from the given JavaMail Session,
using the configured protocol.
|
String |
getUsername() |
void |
send(javax.mail.internet.MimeMessage mimeMessage)
Send the given JavaMail MIME message.
|
void |
send(javax.mail.internet.MimeMessage[] mimeMessages)
Send the given array of JavaMail MIME messages in batch.
|
void |
send(MimeMessagePreparator mimeMessagePreparator)
Send the JavaMail MIME message prepared by the given MimeMessagePreparator.
|
void |
send(MimeMessagePreparator[] mimeMessagePreparators)
Send the JavaMail MIME messages prepared by the given MimeMessagePreparators.
|
void |
send(SimpleMailMessage simpleMessage)
Send the given simple mail message.
|
void |
send(SimpleMailMessage[] simpleMessages)
Send the given array of simple mail messages in batch.
|
void |
setDefaultEncoding(String defaultEncoding)
Set the default encoding to use for
MimeMessages
created by this instance. |
void |
setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap)
Set the default Java Activation
FileTypeMap to use for
MimeMessages created by this instance. |
void |
setHost(String host)
Set the mail server host, typically an SMTP host.
|
void |
setJavaMailProperties(Properties javaMailProperties)
Set JavaMail properties for the
Session. |
void |
setPassword(String password)
Set the password for the account at the mail host, if any.
|
void |
setPort(int port)
Set the mail server port.
|
void |
setProtocol(String protocol)
Set the mail protocol.
|
void |
setSession(javax.mail.Session session)
Set the JavaMail
Session, possibly pulled from JNDI. |
void |
setUsername(String username)
Set the username for the account at the mail host, if any.
|
public static final String DEFAULT_PROTOCOL
public static final int DEFAULT_PORT
public JavaMailSenderImpl()
JavaMailSenderImpl class.
Initializes the "defaultFileTypeMap"
property with a default ConfigurableMimeFileTypeMap.
public void setJavaMailProperties(Properties javaMailProperties)
Session.
A new Session will be created with those properties.
Use either this method or setSession(javax.mail.Session), but not both.
Non-default properties in this instance will override given
javaMailProperties - JavaMail properties.public Properties getJavaMailProperties()
Useful for specifying entries directly, for example via "javaMailProperties[mail.smtp.auth]".
public void setSession(javax.mail.Session session)
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.
session - setJavaMailProperties(java.util.Properties)public javax.mail.Session getSession()
Session,
lazily initializing it if hasn't been specified explicitly.public void setProtocol(String protocol)
protocol - protocolpublic String getProtocol()
public void setHost(String host)
Default is the default host of the underlying JavaMail Session.
host - hostpublic String getHost()
public void setPort(int port)
Default is DEFAULT_PORT, letting JavaMail use the default
SMTP port (25).
port - public int getPort()
public void setUsername(String username)
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(java.util.Properties).
username - usernamesetSession(javax.mail.Session),
setPassword(java.lang.String)public String getUsername()
public void setPassword(String password)
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(java.util.Properties).
password - passwordsetSession(javax.mail.Session),
setUsername(java.lang.String)public String getPassword()
public void setDefaultEncoding(String defaultEncoding)
MimeMessages
created by this instance.
Such an encoding will be auto-detected by MimeMessageHelper.
defaultEncoding - defaultEncodingpublic String getDefaultEncoding()
MimeMessages,
or null if none.public void setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap)
FileTypeMap to use for
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).
defaultFileTypeMap - defaultFileTypeMapMimeMessageHelper.setFileTypeMap(javax.activation.FileTypeMap)public FileTypeMap getDefaultFileTypeMap()
FileTypeMap for
MimeMessages, or null if none.public void send(SimpleMailMessage simpleMessage) throws MailException
MailSendersend 在接口中 MailSendersimpleMessage - the message to sendMailExceptionpublic void send(SimpleMailMessage[] simpleMessages) throws MailException
MailSendersend 在接口中 MailSendersimpleMessages - the messages to sendMailExceptionpublic javax.mail.internet.MimeMessage createMimeMessage()
MimeMessageHelper, which will use
the carried encoding and FileTypeMap unless explicitly overridden.createMimeMessage 在接口中 JavaMailSendersetDefaultEncoding(java.lang.String),
setDefaultFileTypeMap(javax.activation.FileTypeMap)public javax.mail.internet.MimeMessage createMimeMessage(InputStream contentStream) throws MailException
JavaMailSendercreateMimeMessage 在接口中 JavaMailSendercontentStream - the raw MIME input stream for the messageMailException - in case of message creation failurepublic void send(javax.mail.internet.MimeMessage mimeMessage)
throws MailException
JavaMailSenderJavaMailSender.createMimeMessage().send 在接口中 JavaMailSendermimeMessage - message to sendMailException - in case of failure when sending the messageJavaMailSender.createMimeMessage()public void send(javax.mail.internet.MimeMessage[] mimeMessages)
throws MailException
JavaMailSenderJavaMailSender.createMimeMessage().send 在接口中 JavaMailSendermimeMessages - messages to sendMailException - in case of failure when sending a messageJavaMailSender.createMimeMessage()public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException
JavaMailSenderAlternative way to prepare MimeMessage instances, instead of
JavaMailSender.createMimeMessage() and JavaMailSender.send(MimeMessage) calls.
Takes care of proper exception conversion.
send 在接口中 JavaMailSendermimeMessagePreparator - the preparator to useMailExceptionpublic void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException
JavaMailSenderAlternative way to prepare MimeMessage instances, instead of
JavaMailSender.createMimeMessage() and JavaMailSender.send(MimeMessage[]) calls.
Takes care of proper exception conversion.
send 在接口中 JavaMailSendermimeMessagePreparators - the preparator to useMailException - in case of failure when sending a messageprotected void doSend(javax.mail.internet.MimeMessage[] mimeMessages,
Object[] originalMessages)
throws MailException
mimeMessages - MimeMessage objects to sendoriginalMessages - corresponding original message objects
that the MimeMessages have been created from (with same array
length and indices as the "mimeMessages" array), if anyorg.springframework.mail.MailAuthenticationException - in case of authentication failureorg.springframework.mail.MailSendException - in case of failure when sending a messageMailExceptionprotected javax.mail.Transport getTransport(javax.mail.Session session)
throws javax.mail.NoSuchProviderException
Can be overridden in subclasses, e.g. to return a mock Transport object.
javax.mail.NoSuchProviderExceptionSession.getTransport(String),
getProtocol()Copyright © 2016. All rights reserved.