Class MailMessageSender

All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, WebServiceMessageSender

public class MailMessageSender extends AbstractWebServiceMessageSender<MailDestinationDescriptor> implements org.springframework.beans.factory.InitializingBean
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][&param-name=param-value]*
where the characters :, ?, and & stand for themselves. The to represents an RFC 822 mailbox. Valid param-name include:
Parameter Names
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

Any mailto: URI supplied by the application is accepted. A URI supplied by a remote peer, such as a WS-Addressing ReplyTo or FaultTo address, is only accepted when a DestinationPolicy accepts it; without a policy, every remote destination is rejected. Use MailDestinationPolicies.allowedRecipients(String...) to state the mailboxes that remote destinations may target.

Since:
1.5.0
See Also:
  • Field Details

    • DEFAULT_RECEIVE_TIMEOUT

      public static final long DEFAULT_RECEIVE_TIMEOUT
      Default timeout for receive operations. Set to 1000 * 60 milliseconds (i.e. 1 minute).
      See Also:
  • Constructor Details

    • MailMessageSender

      public MailMessageSender()
  • Method Details

    • setFrom

      public void setFrom(String from) throws jakarta.mail.internet.AddressException
      Sets the from address to use when sending request messages.
      Throws:
      jakarta.mail.internet.AddressException
    • setJavaMailProperties

      public void setJavaMailProperties(Properties javaMailProperties)
      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.

    • 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.
    • setVerifyResponseSender

      public void setVerifyResponseSender(boolean verifyResponseSender)
      Set whether a received response must originate from the address the request was sent to before it is accepted as the reply. Defaults to false.

      Enabling this adds a defense-in-depth check against forged responses. Do not enable it if legitimate replies may arrive from a different address than the request destination.

      Parameters:
      verifyResponseSender - whether to validate the response originates from the address of the request
      Since:
      3.1.10
    • setSession

      public void setSession(jakarta.mail.Session session)
      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.

      See Also:
    • setStoreUri

      public void setStoreUri(String storeUri)
      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:
      • Session.getStore(URLName)
    • setTransportUri

      public void setTransportUri(String transportUri)
      Sets the JavaMail Transport URI to be used for sending response messages. Typically, takes the form of smtp://user:password@host:port. Setting this property is required.

      For example, smtp://john:[email protected]

      See Also:
      • Session.getTransport(URLName)
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • createConnection

      public WebServiceConnection createConnection(URI uri) throws IOException
      Description copied from interface: WebServiceMessageSender
      Create a new WebServiceConnection to the specified URI.
      Specified by:
      createConnection in interface WebServiceMessageSender
      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
      Create a WebServiceMessageSender.DestinationDescriptor for the given uri and uriSource.
      Specified by:
      createDescriptor in class AbstractWebServiceMessageSender<MailDestinationDescriptor>
      Parameters:
      uri - the URI to check
      uriSource - the source of the URI
      Returns:
      a suitable descriptor