Class MailMessageSender
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, WebServiceMessageSender
WebServiceMessageSender implementation that uses Mail MimeMessages.
Requires a transport and store URI to be set.
Calling WebServiceConnection.receive(WebServiceMessageFactory) on connections
created by this message sender will result in a blocking call, for the amount of
milliseconds specified by the receiveSleepTime
property. This will give the server time to formulate a response message. By default,
this property is set to 1 minute. For a proper request-response conversation to work,
this property value must not be smaller the
pollingInterval property of
the server-side message receiver polling strategy.
This message sender supports URI's of the following format:
mailto:<to>[?param-name=param-value][¶m-name=param-value]*
where the characters :, ?, and & stand for themselves. The
to represents an RFC 822 mailbox. Valid param-name include:
| param-name | Description |
|---|---|
subject |
The subject of the request message. |
Some examples of email URIs are: mailto:[email protected]
mailto:[email protected]@?subject=SOAP%20Test
For WebServiceMessageSender.UriSource.APPLICATION, default checks accept any mailto: URI. For
WebServiceMessageSender.UriSource.REMOTE, default checks require a well-formed mailbox in the
MailDestinationDescriptor (parsable To, extractable host, basic
header-injection guards); reject localhost and *.localhost in the
mailbox host segment. Use a WebServiceMessageSender.DestinationPolicy for
domain allowlists, header rules, or other mail-specific validation.
- Since:
- 1.5.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface WebServiceMessageSender
WebServiceMessageSender.DestinationDescriptor, WebServiceMessageSender.DestinationPolicy<D>, WebServiceMessageSender.UriSource -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault timeout for receive operations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateConnection(URI uri) Create a newWebServiceConnectionto the specified URI.protected MailDestinationDescriptorcreateDescriptor(URI uri, WebServiceMessageSender.UriSource uriSource) protected Predicate<MailDestinationDescriptor> defaultChecks(WebServiceMessageSender.UriSource uriSource) Return the default checks to apply for the givenWebServiceMessageSender.UriSource.protected booleanvoidSets the from address to use when sending request messages.voidsetJavaMailProperties(Properties javaMailProperties) Set JavaMail properties for theSession.voidsetReceiveSleepTime(long receiveSleepTime) Set the sleep time to use for receive calls, in milliseconds.voidsetSession(jakarta.mail.Session session) Set the JavaMailSession, possibly pulled from JNDI.voidsetStoreUri(String storeUri) Sets the JavaMail Store URI to be used for retrieving response messages.voidsetTransportUri(String transportUri) Sets the JavaMail Transport URI to be used for sending response messages.Methods inherited from class AbstractWebServiceMessageSender
getDestinationPolicy, setDestinationPolicy, supportsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface WebServiceMessageSender
supports
-
Field Details
-
DEFAULT_RECEIVE_TIMEOUT
public static final long DEFAULT_RECEIVE_TIMEOUTDefault timeout for receive operations. Set to 1000 * 60 milliseconds (i.e. 1 minute).- See Also:
-
-
Constructor Details
-
MailMessageSender
public MailMessageSender()
-
-
Method Details
-
setFrom
Sets the from address to use when sending request messages.- Throws:
jakarta.mail.internet.AddressException
-
setJavaMailProperties
Set JavaMail properties for theSession.A new
Sessionwill be created with those properties. Use either this method orsetSession(Session), but not both.Non-default properties in this instance will override given JavaMail properties.
-
setReceiveSleepTime
public void setReceiveSleepTime(long receiveSleepTime) Set the sleep time to use for receive calls, in milliseconds. The default is 1000 * 60 ms, that is 1 minute. -
setSession
public void setSession(jakarta.mail.Session session) Set the JavaMailSession, possibly pulled from JNDI.Default is a new
Sessionwithout 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 theSession.- See Also:
-
setStoreUri
Sets the JavaMail Store URI to be used for retrieving response messages. Typically, takes the form of[imap|pop3]://user:password@host:port/INBOX. Setting this property is required.For example,
imap://john:[email protected]/INBOX- See Also:
-
setTransportUri
Sets the JavaMail Transport URI to be used for sending response messages. Typically, takes the form ofsmtp://user:password@host:port. Setting this property is required.For example,
smtp://john:[email protected]- See Also:
-
afterPropertiesSet
-
createConnection
Description copied from interface:WebServiceMessageSenderCreate a newWebServiceConnectionto the specified URI.- Specified by:
createConnectionin interfaceWebServiceMessageSender- Parameters:
uri- the URI to open a connection to- Returns:
- the new connection
- Throws:
IOException- in case of I/O errors
-
createDescriptor
protected MailDestinationDescriptor createDescriptor(URI uri, WebServiceMessageSender.UriSource uriSource) Description copied from class:AbstractWebServiceMessageSender- Specified by:
createDescriptorin classAbstractWebServiceMessageSender<MailDestinationDescriptor>- Parameters:
uri- the URI to checkuriSource- the source of the URI- Returns:
- a suitable descriptor
-
defaultChecks
protected Predicate<MailDestinationDescriptor> defaultChecks(WebServiceMessageSender.UriSource uriSource) Description copied from class:AbstractWebServiceMessageSenderReturn the default checks to apply for the givenWebServiceMessageSender.UriSource.- Specified by:
defaultChecksin classAbstractWebServiceMessageSender<MailDestinationDescriptor>- Returns:
- the default checks to apply
-
remoteDefaultChecks
-