|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.mail.javamail.JavaMailSenderImpl
public class JavaMailSenderImpl
Production implementation of the JavaMailSender interface. Supports both JavaMail MimeMessages and Spring SimpleMailMessages. Can also be used as plain MailSender implementation.
Allows for defining all settings locally as bean properties. Alternatively, a pre-configured JavaMail 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.
MimeMessage
,
SimpleMailMessage
,
MailSender
,
setJavaMailProperties(java.util.Properties)
,
setHost(java.lang.String)
,
setPort(int)
,
setUsername(java.lang.String)
,
setPassword(java.lang.String)
,
setSession(javax.mail.Session)
Field Summary | |
---|---|
static int |
DEFAULT_PORT
|
static String |
DEFAULT_PROTOCOL
|
protected org.apache.commons.logging.Log |
logger
|
Constructor Summary | |
---|---|
JavaMailSenderImpl()
Constructor for JavaMailSenderImpl. |
Method Summary | |
---|---|
MimeMessage |
createMimeMessage()
This implementation creates a SmartMimeMessage, holding the specified default encoding and default FileTypeMap. |
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(MimeMessage[] mimeMessages,
Object[] originalMessages)
Actually send the given array of MimeMessages via JavaMail. |
String |
getDefaultEncoding()
Return the default encoding for MimeMessages, or null if none. |
FileTypeMap |
getDefaultFileTypeMap()
Return the default Java Activation FileTypeMap for MimeMessages, or null if none. |
String |
getHost()
Return the mail server host. |
String |
getPassword()
Return the password for the account at the mail host. |
int |
getPort()
Return the mail server port. |
String |
getProtocol()
Return the mail protocol. |
Session |
getSession()
Return the JavaMail Session. |
protected Transport |
getTransport(Session session)
Get a Transport object for the given JavaMail Session. |
String |
getUsername()
Return the username for the account at the mail host. |
void |
send(MimeMessage mimeMessage)
Send the given JavaMail MIME message. |
void |
send(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 JavaMailSender. |
void |
setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap)
Set the default Java Activation FileTypeMap to use for MimeMessages created by this JavaMailSender. |
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(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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_PROTOCOL
public static final int DEFAULT_PORT
protected final org.apache.commons.logging.Log logger
Constructor Detail |
---|
public JavaMailSenderImpl()
Initializes the "defaultFileTypeMap" property with a default ConfigurableMimeFileTypeMap.
setDefaultFileTypeMap(javax.activation.FileTypeMap)
,
ConfigurableMimeFileTypeMap
Method Detail |
---|
public void setJavaMailProperties(Properties javaMailProperties)
Non-default properties in this MailSender will override given JavaMail properties.
setSession(javax.mail.Session)
public void setSession(Session session)
If using a pre-configured Session, non-default properties in this MailSender will override the settings in the Session.
setJavaMailProperties(java.util.Properties)
public Session getSession()
public void setProtocol(String protocol)
public String getProtocol()
public void setHost(String host)
public String getHost()
public void setPort(int 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 JavaMailSenderImpl's "javaMailProperties".
setJavaMailProperties(java.util.Properties)
,
setSession(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 JavaMailSenderImpl's "javaMailProperties".
setJavaMailProperties(java.util.Properties)
,
setSession(javax.mail.Session)
,
setUsername(java.lang.String)
public String getPassword()
public void setDefaultEncoding(String defaultEncoding)
MimeMessageHelper
public String getDefaultEncoding()
null
if none.
public void setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap)
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).
MimeMessageHelper.setFileTypeMap(javax.activation.FileTypeMap)
,
ConfigurableMimeFileTypeMap
public FileTypeMap getDefaultFileTypeMap()
null
if none.
public void send(SimpleMailMessage simpleMessage) throws MailException
MailSender
send
in interface MailSender
simpleMessage
- the message to send
MailParseException
- in case of failure when parsing the message
MailAuthenticationException
- in case of authentication failure
MailSendException
- in case of failure when sending the message
MailException
public void send(SimpleMailMessage[] simpleMessages) throws MailException
MailSender
send
in interface MailSender
simpleMessages
- the messages to send
MailParseException
- in case of failure when parsing a message
MailAuthenticationException
- in case of authentication failure
MailSendException
- in case of failure when sending a message
MailException
public MimeMessage createMimeMessage()
createMimeMessage
in interface JavaMailSender
setDefaultEncoding(java.lang.String)
,
setDefaultFileTypeMap(javax.activation.FileTypeMap)
,
MimeMessageHelper
public MimeMessage createMimeMessage(InputStream contentStream) throws MailException
JavaMailSender
createMimeMessage
in interface JavaMailSender
contentStream
- the raw MIME input stream for the message
MailParseException
- in case of message creation failure
MailException
public void send(MimeMessage mimeMessage) throws MailException
JavaMailSender
send
in interface JavaMailSender
mimeMessage
- message to send
MailAuthenticationException
- in case of authentication failure
MailSendException
- in case of failure when sending the message
MailException
JavaMailSender.createMimeMessage()
public void send(MimeMessage[] mimeMessages) throws MailException
JavaMailSender
send
in interface JavaMailSender
mimeMessages
- messages to send
MailAuthenticationException
- in case of authentication failure
MailSendException
- in case of failure when sending a message
MailException
JavaMailSender.createMimeMessage()
public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException
JavaMailSender
send
in interface JavaMailSender
mimeMessagePreparator
- the preparator to use
MailPreparationException
- in case of failure when preparing the message
MailParseException
- in case of failure when parsing the message
MailAuthenticationException
- in case of authentication failure
MailSendException
- in case of failure when sending the message
MailException
public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException
JavaMailSender
send
in interface JavaMailSender
mimeMessagePreparators
- the preparator to use
MailPreparationException
- in case of failure when preparing a message
MailParseException
- in case of failure when parsing a message
MailAuthenticationException
- in case of authentication failure
MailSendException
- in case of failure when sending a message
MailException
protected void doSend(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 any
MailAuthenticationException
- in case of authentication failure
MailSendException
- in case of failure when sending a message
MailException
protected Transport getTransport(Session session) throws NoSuchProviderException
NoSuchProviderException
Session.getTransport()
,
getProtocol()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |