Class MailPlugin

java.lang.Object
org.imixs.workflow.engine.plugins.AbstractPlugin
org.imixs.workflow.engine.plugins.MailPlugin
All Implemented Interfaces:
Plugin

public class MailPlugin extends AbstractPlugin
This plug-in supports a Mail interface to send a email to a list of recipients. The mail content can be defined by the corresponding BPMN event. The content of the email can either be plain text or HTML. The plug-in uses a JNID messaging session named 'org.imixs.workflow.mail'. The JNDI resource can be customized by the deployment constructor. The e-mail message can be canceled by the application or another plug-in by setting the attribute keyMailInactive=true
Author:
Ralph Soika
  • Field Details

  • Constructor Details

    • MailPlugin

      public MailPlugin()
  • Method Details

    • run

      public ItemCollection run(ItemCollection documentContext, ItemCollection documentActivity) throws PluginException
      The run method creates a mailMessage object if recipients are defined by the corresponding BPMN event. The mail message will finally be send in the close method. This mechanism avoids that a mail is send before all plug-ins were processed correctly.
      Parameters:
      documentContext - the workitem to be processed
      documentActivity - the workflow event containing the processing instructions
      Returns:
      updated workitem for further processing
      Throws:
      PluginException
    • close

      public void close(boolean rollbackTransaction) throws PluginException
      Send the mail if the object 'mailMessage' is not null. The method lookups the mail session from the session context.
      Specified by:
      close in interface Plugin
      Overrides:
      close in class AbstractPlugin
      Parameters:
      rollbackTransaction - indicates if the current transaction will be rolled back.
      Throws:
      PluginException
    • getFrom

      public String getFrom(ItemCollection documentContext, ItemCollection documentActivity)
      Computes the sender name. A sender can be defined by the event property 'namMailFrom' or by the system property 'mail.defaultSender'. If no sender is defined, the method takes the current username. This method can be overwritten by subclasses.
      Parameters:
      documentContext -
      documentActivity -
      Returns:
      String - mail seder
    • getReplyTo

      public String getReplyTo(ItemCollection documentContext, ItemCollection documentActivity)
      Computes the replyTo address from current workflow activity. This method can be overwritten by subclasses.
      Parameters:
      documentContext -
      documentActivity -
      Returns:
      String - replyTo address
    • getSubject

      public String getSubject(ItemCollection documentContext, ItemCollection documentActivity) throws PluginException
      Computes the mail subject from the current workflow activity. This method can be overwritten by subclasses.
      Parameters:
      documentContext -
      documentActivity -
      Returns:
      String - mail subject
      Throws:
      PluginException
    • getRecipients

      public List<String> getRecipients(ItemCollection documentContext, ItemCollection documentActivity)
      Computes the mail Recipients from the current workflow activity. This method can be overwritten by subclasses.
      Parameters:
      documentContext -
      documentActivity -
      Returns:
      String list of Recipients
    • getRecipientsCC

      public List<String> getRecipientsCC(ItemCollection documentContext, ItemCollection documentActivity)
      Computes the mail RecipientsCC from the current workflow activity. This method can be overwritten by subclasses.
      Parameters:
      documentContext -
      documentActivity -
      Returns:
      String list of Recipients
    • getRecipientsBCC

      public List<String> getRecipientsBCC(ItemCollection documentContext, ItemCollection documentActivity)
      Computes the mail RecipientsBCC from the current workflow activity. This method can be overwritten by subclasses.
      Parameters:
      documentContext -
      documentActivity -
      Returns:
      String list of Recipients
    • getBody

      public String getBody(ItemCollection documentContext, ItemCollection documentActivity) throws PluginException
      Computes the mail body from the current workflow event. The method also updates the internal flag HTMLMail to indicate if the mail is send as HTML mail. In case the content contains a XSL Template, the template will be processed with the current document structure. The method can be overwritten by subclasses.
      Parameters:
      documentContext -
      documentActivity -
      Returns:
      String - mail subject
      Throws:
      PluginException
    • transformXSLBody

      public String transformXSLBody(ItemCollection documentContext, String xslTemplate) throws PluginException
      This method performs a XSL transformation based on the current Mail Body text. The xml source is generated form the current document context. encoding is set to UTF-8
      Returns:
      translated email body
      Throws:
      PluginException
    • initMailMessage

      public void initMailMessage() throws jakarta.mail.internet.AddressException, jakarta.mail.MessagingException
      initializes a new mail Message object
      Throws:
      jakarta.mail.internet.AddressException
      jakarta.mail.MessagingException
    • getInternetAddress

      public jakarta.mail.internet.InternetAddress getInternetAddress(String aAddr) throws jakarta.mail.internet.AddressException
      This method creates an InternetAddress from a string. If the string has illegal characters like whitespace the string will be surrounded with "". The method can be overwritten by subclasses to return a different mail-address name or lookup a mail attribute in a directory.
      Parameters:
      aAddr - string
      Returns:
      InternetAddress
      Throws:
      jakarta.mail.internet.AddressException
    • getMailSession

      public jakarta.mail.Session getMailSession()
      This method returns the mail session object.
    • getMailMessage

      public jakarta.mail.Message getMailMessage()
    • getMultipart

      public jakarta.mail.Multipart getMultipart()
    • isHTMLMail

      public boolean isHTMLMail()
      Return true if the mail body contains HTML content.
      Returns:
    • getCharSet

      public String getCharSet()
    • setCharSet

      public void setCharSet(String charSet)
    • getContentType

      public String getContentType()
      This method returns a string representing the mail content type. The content type depends on the content of the mail body (html or plaintext) and contains optional the character set. If the mail is a HTML mail then the returned string contains 'text/html' otherwise it will contain 'text/plain'. The content
      Returns: