Class MailPlugin
java.lang.Object
org.imixs.workflow.engine.plugins.AbstractPlugin
org.imixs.workflow.engine.plugins.MailPlugin
- All Implemented Interfaces:
Plugin
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 Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class org.imixs.workflow.engine.plugins.AbstractPlugin
INVALID_ITEMVALUE_FORMAT, INVALID_PROPERTYVALUE_FORMAT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close
(boolean rollbackTransaction) Send the mail if the object 'mailMessage' is not null.getBody
(ItemCollection documentContext, ItemCollection documentActivity) Computes the mail body from the current workflow event.This method returns a string representing the mail content type.getFrom
(ItemCollection documentContext, ItemCollection documentActivity) Computes the sender name.jakarta.mail.internet.InternetAddress
getInternetAddress
(String aAddr) This method creates an InternetAddress from a string.jakarta.mail.Message
jakarta.mail.Session
This method returns the mail session object.jakarta.mail.Multipart
getRecipients
(ItemCollection documentContext, ItemCollection documentActivity) Computes the mail Recipients from the current workflow activity.getRecipientsBCC
(ItemCollection documentContext, ItemCollection documentActivity) Computes the mail RecipientsBCC from the current workflow activity.getRecipientsCC
(ItemCollection documentContext, ItemCollection documentActivity) Computes the mail RecipientsCC from the current workflow activity.getReplyTo
(ItemCollection documentContext, ItemCollection documentActivity) Computes the replyTo address from current workflow activity.getSubject
(ItemCollection documentContext, ItemCollection documentActivity) Computes the mail subject from the current workflow activity.void
initializes a new mail Message objectboolean
Return true if the mail body contains HTML content.run
(ItemCollection documentContext, ItemCollection documentActivity) The run method creates a mailMessage object if recipients are defined by the corresponding BPMN event.void
setCharSet
(String charSet) transformXSLBody
(ItemCollection documentContext, String xslTemplate) This method performs a XSL transformation based on the current Mail Body text.Methods inherited from class org.imixs.workflow.engine.plugins.AbstractPlugin
getCtx, getWorkflowService, init, mergeFieldList, uniqueList
-
Field Details
-
ERROR_INVALID_XSL_FORMAT
- See Also:
-
ERROR_MAIL_MESSAGE
- See Also:
-
MAIL_SESSION_NAME
- See Also:
-
CONTENTTYPE_TEXT_PLAIN
- See Also:
-
CONTENTTYPE_TEXT_HTML
- See Also:
-
INVALID_ADDRESS
- See Also:
-
-
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 processeddocumentActivity
- the workflow event containing the processing instructions- Returns:
- updated workitem for further processing
- Throws:
PluginException
-
close
Send the mail if the object 'mailMessage' is not null. The method lookups the mail session from the session context.- Specified by:
close
in interfacePlugin
- Overrides:
close
in classAbstractPlugin
- Parameters:
rollbackTransaction
- indicates if the current transaction will be rolled back.- Throws:
PluginException
-
getFrom
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
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
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.MessagingExceptioninitializes 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
-
setCharSet
-
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:
-