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 Summary
Fields Modifier and Type Field Description static StringCONTENTTYPE_TEXT_HTMLstatic StringCONTENTTYPE_TEXT_PLAINstatic StringERROR_INVALID_XSL_FORMATstatic StringERROR_MAIL_MESSAGEstatic StringINVALID_ADDRESSstatic StringMAIL_SESSION_NAME-
Fields inherited from class org.imixs.workflow.engine.plugins.AbstractPlugin
INVALID_ITEMVALUE_FORMAT, INVALID_PROPERTYVALUE_FORMAT
-
-
Constructor Summary
Constructors Constructor Description MailPlugin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose(boolean rollbackTransaction)Send the mail if the object 'mailMessage' is not null.StringgetBody(ItemCollection documentContext, ItemCollection documentActivity)Computes the mail body from the current workflow event.StringgetCharSet()StringgetContentType()This method returns a string representing the mail content type.StringgetFrom(ItemCollection documentContext, ItemCollection documentActivity)Computes the sender name.jakarta.mail.internet.InternetAddressgetInternetAddress(String aAddr)This method creates an InternetAddress from a string.jakarta.mail.MessagegetMailMessage()jakarta.mail.SessiongetMailSession()This method returns the mail session object.jakarta.mail.MultipartgetMultipart()List<String>getRecipients(ItemCollection documentContext, ItemCollection documentActivity)Computes the mail Recipients from the current workflow activity.List<String>getRecipientsBCC(ItemCollection documentContext, ItemCollection documentActivity)Computes the mail RecipientsBCC from the current workflow activity.List<String>getRecipientsCC(ItemCollection documentContext, ItemCollection documentActivity)Computes the mail RecipientsCC from the current workflow activity.StringgetReplyTo(ItemCollection documentContext, ItemCollection documentActivity)Computes the replyTo address from current workflow activity.StringgetSubject(ItemCollection documentContext, ItemCollection documentActivity)Computes the mail subject from the current workflow activity.voidinitMailMessage()initializes a new mail Message objectbooleanisHTMLMail()Return true if the mail body contains HTML content.ItemCollectionrun(ItemCollection documentContext, ItemCollection documentActivity)The run method creates a mailMessage object if recipients are defined by the corresponding BPMN event.voidsetCharSet(String charSet)StringtransformXSLBody(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 Detail
-
ERROR_INVALID_XSL_FORMAT
public static final String ERROR_INVALID_XSL_FORMAT
- See Also:
- Constant Field Values
-
ERROR_MAIL_MESSAGE
public static final String ERROR_MAIL_MESSAGE
- See Also:
- Constant Field Values
-
MAIL_SESSION_NAME
public static final String MAIL_SESSION_NAME
- See Also:
- Constant Field Values
-
CONTENTTYPE_TEXT_PLAIN
public static final String CONTENTTYPE_TEXT_PLAIN
- See Also:
- Constant Field Values
-
CONTENTTYPE_TEXT_HTML
public static final String CONTENTTYPE_TEXT_HTML
- See Also:
- Constant Field Values
-
INVALID_ADDRESS
public static final String INVALID_ADDRESS
- See Also:
- Constant Field Values
-
-
Method Detail
-
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.- Throws:
PluginException
-
close
public void close(boolean rollbackTransaction) throws PluginExceptionSend the mail if the object 'mailMessage' is not null. The method lookups the mail session from the session context.- Specified by:
closein interfacePlugin- Overrides:
closein classAbstractPlugin- 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.MessagingExceptioninitializes a new mail Message object- Throws:
jakarta.mail.internet.AddressExceptionjakarta.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:
-
-