Class MailSender

All Implemented Interfaces:
FrankElement, HasApplicationContext, HasName, HasPhysicalDestination, IConfigurable, IScopeProvider, ISender, ISenderWithParameters, IWithParameters, NameAware, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle

@Category(ADVANCED) public class MailSender extends AbstractMailSender implements HasPhysicalDestination
sender that sends a mail specified by an XML message.

Sample email.xml:

<email>
    <recipients>
        <recipient type="to">***@hotmail.com</recipient>
        <recipient type="cc">***@gmail.com</recipient>
    </recipients>
    <from name="*** ***">***@yahoo.com</from>
    <subject>This is the subject</subject>
    <threadTopic>subject</threadTopic>
    <message>This is the message</message>
    <messageType>text/plain</messageType><!-- Optional -->
    <messageBase64>false</messageBase64><!-- Optional -->
    <charset>UTF-8</charset><!-- Optional -->
    <attachments>
        <attachment name="filename1.txt">This is the first attachment</attachment>
        <attachment name="filename2.pdf" base64="true">JVBERi0xLjQKCjIgMCBvYmoKPDwvVHlwZS9YT2JqZWN0L1N1YnR5cGUvSW1...vSW5mbyA5IDAgUgo+PgpzdGFydHhyZWYKMzQxNDY2CiUlRU9GCg==</attachment>
        <attachment name="filename3.pdf" url="file:/c:/filename3.pdf"/>
        <attachment name="filename4.pdf" sessionKey="fileContent"/>
    </attachments><!-- Optional -->
</email>

Notice: the XML message must be valid XML. Therefore, especially the message element must be plain text or be wrapped as CDATA. Example:

<message><![CDATA[<h1>This is a HtmlMessage</h1>]]></message>

The sessionKey attribute for attachment can contain an inputstream or a string. Other types are not supported at this moment.

The attribute order for attachments is as follows:

  1. sessionKey
  2. url
  3. value of the attachment element

The base64 attribute is only used when the value of the PipeLineSession variable sessionKey is a String object or when the value of the attachment element is used. If base64=true then the value will be decoded before it's used.

Compilation and Deployment Note: mail.jar (v1.2) and activation.jar must appear BEFORE j2ee.jar. Otherwise, errors like the following might occur: NoClassDefFoundException: com/sun/mail/util/MailDateFormat

Author:
Johan Verrips, Gerrit van Brakel
  • Constructor Details

    • MailSender

      public MailSender()
  • Method Details

    • configure

      public void configure() throws ConfigurationException
      Description copied from interface: IConfigurable
      Configure this component.

      configure() is called once at startup of the framework in the configure method of the owner of this IConfigurable. Purpose of this method is to check whether the static configuration of the object is correct. As much as possible class-instantiating should take place in the configure(), to improve performance.

      In the case of a container, this will propagate the configure signal to all components that apply.

      Specified by:
      configure in interface IConfigurable
      Overrides:
      configure in class AbstractMailSender
      Throws:
      ConfigurationException - in case it was not able to configure the component.
    • start

      public void start()
      Create a session to validate connectivity
      Specified by:
      start in interface ISender
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Overrides:
      start in class AbstractSender
    • createSession

      protected jakarta.mail.Session createSession()
      Create the session during runtime
    • sendEmail

      public void sendEmail(AbstractMailSender.MailSessionBase mailSession) throws SenderException
      Specified by:
      sendEmail in class AbstractMailSender
      Throws:
      SenderException
    • createMailSession

      protected MailSender.MailSession createMailSession() throws SenderException
      Specified by:
      createMailSession in class AbstractMailSender
      Throws:
      SenderException
    • setSmtpHost

      public void setSmtpHost(String newSmtpHost)
      Name of the SMTP-host by which the messages are to be sent
    • setSmtpPort

      public void setSmtpPort(int newSmtpPort)
      Port of the SMTP-host by which the messages are to be sent. Port 465 means implicit SSL, port 587 means no ssl by default, but the connection is upgraded to ssl by using startTls if #useSsl is true
      Default value
      25
    • getPhysicalDestinationName

      public String getPhysicalDestinationName()
      Specified by:
      getPhysicalDestinationName in interface HasPhysicalDestination