JavaMailSender interface,
supporting both JavaMail MimeMessages and Spring
SimpleMailMessages. Can also be used as a
plain org.springframework.mail.MailSender implementation.
Allows for defining all settings locally as bean properties.
Alternatively, a pre-configured JavaMail jakarta. 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.
jakarta.mail.internet.MimeMessage , jakarta.mail.Session , setSession, setJavaMailProperties, setHost, setPort, setUsername, setPassword
| Modifier and Type | Field and Description |
|---|---|
| public static final int | DEFAULT_PORT
The default port: -1. |
| public static final String | DEFAULT_PROTOCOL
The default protocol: 'smtp'. |
| private String | |
| private FileTypeMap | |
| private static final String | |
| private String | |
| private Properties | |
| private String | |
| private int | |
| private String | |
| private Session | |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Transport | Returns: the connected Transport objectObtain and connect a Transport from the underlying JavaMail Session, passing in the specified host, port, username, and password. |
| public MimeMessage | createMimeMessage()
Implements org. This implementation creates a SmartMimeMessage, holding the specified default encoding and default FileTypeMap. |
| public MimeMessage | createMimeMessage(InputStream
the raw MIME input stream for the message contentStream)Implements org. 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[]
the MimeMessage objects to send mimeMessages, Object[] corresponding original message objects
that the MimeMessages have been created from (with same array
length and indices as the "mimeMessages" array), if any originalMessages)Actually send the given array of MimeMessages via JavaMail. |
| public String | |
| public FileTypeMap | getDefaultFileTypeMap()
Return the default Java Activation |
| public String | |
| public Properties | getJavaMailProperties()
Allow |
| public String | |
| public int | |
| public String | |
| public synchronized Session | getSession()
Return the JavaMail |
| protected Transport | getTransport(Session session)
Obtain a Transport object from the given JavaMail Session, using the configured protocol. |
| public String | |
| public void | send(SimpleMailMessage...
the messages to send simpleMessages)Implements org. Send the given array of simple mail messages in batch. |
| public void | send(MimeMessage...
messages to send mimeMessages)Implements org. Send the given array of JavaMail MIME messages in batch. |
| public void | setDefaultEncoding(String defaultEncoding)
Set the default encoding to use for |
| public void | setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap)
Set the default Java Activation |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public synchronized void | |
| public void | |
| public void |
| DEFAULT_PORT | back to summary |
|---|---|
| public static final int DEFAULT_PORT The default port: -1. | |
| DEFAULT_PROTOCOL | back to summary |
|---|---|
| public static final String DEFAULT_PROTOCOL The default protocol: 'smtp'. | |
| defaultEncoding | back to summary |
|---|---|
| private String defaultEncoding
| |
| defaultFileTypeMap | back to summary |
|---|---|
| private FileTypeMap defaultFileTypeMap
| |
| HEADER_MESSAGE_ID | back to summary |
|---|---|
| private static final String HEADER_MESSAGE_ID | |
| host | back to summary |
|---|---|
| private String host
| |
| javaMailProperties | back to summary |
|---|---|
| private Properties javaMailProperties | |
| password | back to summary |
|---|---|
| private String password
| |
| port | back to summary |
|---|---|
| private int port | |
| protocol | back to summary |
|---|---|
| private String protocol
| |
| session | back to summary |
|---|---|
| private Session session
| |
| username | back to summary |
|---|---|
| private String username
| |
| JavaMailSenderImpl | back to summary |
|---|---|
| public JavaMailSenderImpl() Create a new instance of the Initializes the | |
| connectTransport | back to summary |
|---|---|
| protected Transport connectTransport() throws MessagingException Obtain and connect a Transport from the underlying JavaMail Session, passing in the specified host, port, username, and password.
| |
| createMimeMessage | back to summary |
|---|---|
| public MimeMessage createMimeMessage() Implements org. This implementation creates a SmartMimeMessage, holding the specified
default encoding and default FileTypeMap. This special defaults-carrying
message will be autodetected by
| |
| createMimeMessage | back to summary |
|---|---|
| public MimeMessage createMimeMessage(InputStream contentStream) throws MailException Implements org. Doc from org. Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender, using the given input stream as the message source.
| |
| doSend | back to summary |
|---|---|
| protected void doSend(MimeMessage[] mimeMessages, Object[] originalMessages) throws MailException Actually send the given array of MimeMessages via JavaMail.
| |
| getDefaultEncoding | back to summary |
|---|---|
| public String getDefaultEncoding() Return the default encoding for
| |
| getDefaultFileTypeMap | back to summary |
|---|---|
| public FileTypeMap getDefaultFileTypeMap() Return the default Java Activation
| |
| getHost | back to summary |
|---|---|
| public String getHost() Return the mail server host.
| |
| getJavaMailProperties | back to summary |
|---|---|
| public Properties getJavaMailProperties() Allow Useful for specifying entries directly, for example via
| |
| getPassword | back to summary |
|---|---|
| public String getPassword() Return the password for the account at the mail host.
| |
| getPort | back to summary |
|---|---|
| public int getPort() Return the mail server port. | |
| getProtocol | back to summary |
|---|---|
| public String getProtocol() Return the mail protocol.
| |
| getSession | back to summary |
|---|---|
| public synchronized Session getSession() Return the JavaMail | |
| getTransport | back to summary |
|---|---|
| protected Transport getTransport(Session session) throws NoSuchProviderException 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. | |
| getUsername | back to summary |
|---|---|
| public String getUsername() Return the username for the account at the mail host.
| |
| send | back to summary |
|---|---|
| public void send(SimpleMailMessage... simpleMessages) throws MailException Implements org. Doc from org. Send the given array of simple mail messages in batch.
| |
| send | back to summary |
|---|---|
| public void send(MimeMessage... mimeMessages) throws MailException Implements org. Doc from org. Send the given array of JavaMail MIME messages in batch.
The messages need to have been created with
| |
| setDefaultEncoding | back to summary |
|---|---|
| public void setDefaultEncoding(String defaultEncoding) Set the default encoding to use for Such an encoding will be auto-detected by | |
| setDefaultFileTypeMap | back to summary |
|---|---|
| public void setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap) Set the default Java Activation A For example, you can specify a custom instance of Spring's
| |
| setHost | back to summary |
|---|---|
| public void setHost(String host) Set the mail server host, typically an SMTP host. Default is the default host of the underlying JavaMail Session. | |
| setJavaMailProperties | back to summary |
|---|---|
| public void setJavaMailProperties(Properties javaMailProperties) Set JavaMail properties for the A new Non-default properties in this instance will override given JavaMail properties. | |
| setPassword | back to summary |
|---|---|
| public void setPassword(String password) Set the password for the account at the mail host, if any. Note that the underlying JavaMail
| |
| setPort | back to summary |
|---|---|
| public void setPort(int port) Set the mail server port. Default is | |
| setProtocol | back to summary |
|---|---|
| public void setProtocol(String protocol) Set the mail protocol. Default is "smtp". | |
| setSession | back to summary |
|---|---|
| public synchronized void setSession(Session session) Set the JavaMail Default is a new If using a pre-configured
| |
| setUsername | back to summary |
|---|---|
| public void setUsername(String username) Set the username for the account at the mail host, if any. Note that the underlying JavaMail
| |
| testConnection | back to summary |
|---|---|
| public void testConnection() throws MessagingException Validate that this instance can connect to the server that it is configured
for. Throws a | |