Package com.groiss.messaging
Interface MessageTemplate
public interface MessageTemplate
Template for creating mail messages. Use the
Admin
-interface to get a template
instance from the database or create a new one. Set the message properties like subject, body, recipients using the setter methods. The message is sent with the send method.
-
Method Summary
Modifier and TypeMethodDescriptionaddAttachment
(BodyPart mbp) Add an attachment to the messageAdd a header field to the message.Add an inline attachment to the mail (optionally).addRecipient
(Recipient rec) Add one recipients.addRecipient
(User user) Add a user as recipient.addRecipient
(String email) Add an email address as recipient.addRecipients
(List<Recipient> recs) Add a list of recipients.Remove all recipients of the given type from the message.Creates a newMessage
object with the data of this MessageTemplate.Returns the application of the template.getBody()
Get the message body.Get the description of the template.getId()
Get the id of the template.Returns aMailQueueItem
which could be set after sending mailget the mail senderGet theMessage
object of MessageTemplate instance which has been created by thesend()
method implicitly or by thecreateMessage()
method explicitly.Get the character set of the messageGet the mime typegetName()
Get the name of the template.Return the list of recipients.Get the optional Reply-to headerGet the optional In-Reply-To header (the message-id of the replying mail)Get the sender mail address.Get the message subject.boolean
isActive()
Is the template activeboolean
Returns true if the mail message is added to the processboolean
isLogged()
Returns true if the message is logged in the mail journalvoid
Make the replacements in subject and body.boolean
send()
Send the message.setActive
(boolean active) Set the message template to active.Set the message context (used for template replacements) to the given activity instance.setAddToProcess
(boolean add) Add the message to the process.Set the message body.setBodyUrl
(String url) Set the message body.setDocument
(DMSObject doc) Set the message context (used for template replacements) to the given document.Set the locale that is used for internationalization of the message.setLogged
(boolean l) Log the message into the mail journal.Set the mail sender for using specific properties for sender and communication settings.setMessageCharset
(String charset) Set the character set for the message (optionally).setMimeType
(String mimetype) Set the mime-type.Set the message context (used for template replacements) to the given process instance.Set the queue behavior.setReplace
(boolean b) Call with true, if you want that replacements are done in subject and body.setReplyTo
(String replyto) Set the Reply-to headersetReplyToMsgId
(String replyto_msgid) Set the In-Reply-To header (the message-id of the replying mail)setSubject
(String subject) Set the message subject.setVariableValue
(String key, Object value) Define a variable for template substitution.
-
Method Details
-
setActive
Set the message template to active. The send method does nothing if the template is inactive. New templates are active by default. -
setMimeType
Set the mime-type.- Parameters:
mimetype
- text/plain or text/html, the latter is the default.
-
setSubject
Set the message subject. Replacements can be defined. -
setBody
Set the message body. Replacements can be defined. -
setBodyUrl
Set the message body.- Parameters:
url
- the url points to a resource in the classpath
-
addRecipients
Add a list of recipients. -
addRecipient
Add one recipients. -
addRecipient
Add a user as recipient. The email field of the user object is used as recipient. -
addRecipient
Add an email address as recipient. -
clearRecipients
Remove all recipients of the given type from the message. -
getRecipients
Return the list of recipients. -
getReplyTo
String getReplyTo()Get the optional Reply-to header -
setReplyTo
Set the Reply-to header -
getReplyToMsgId
String getReplyToMsgId()Get the optional In-Reply-To header (the message-id of the replying mail) -
getSenderAddress
String getSenderAddress()Get the sender mail address. -
addHeader
Add a header field to the message. -
setReplyToMsgId
Set the In-Reply-To header (the message-id of the replying mail) -
getMessageCharset
String getMessageCharset()Get the character set of the message -
setMessageCharset
Set the character set for the message (optionally). If not set, the system default is taken when sending mail. -
setLogged
Log the message into the mail journal. -
setAddToProcess
Add the message to the process. -
setProcessInstance
Set the message context (used for template replacements) to the given process instance. -
setActivityInstance
Set the message context (used for template replacements) to the given activity instance. -
setDocument
Set the message context (used for template replacements) to the given document. -
setVariableValue
Define a variable for template substitution. Note, that this method implicitly sets a context.- Parameters:
key
- a key for referencing the objectvalue
- the value, can be a string, number, date, persistent, etc.
-
setLocale
Set the locale that is used for internationalization of the message. -
addAttachment
Add an attachment to the message -
addInlineBodyPart
Add an inline attachment to the mail (optionally). Inline attachments are used by HTML mails only, i.e. the mimetype "text/html" must be set! -
setQueueAction
Set the queue behavior. Note, that this method sets the mail sender to the default sender, if none is defined. A later call of setMailSender will overwrite this setting.- Parameters:
ma
- one of the mail action values: QUEUE, DEFFERRED, NO_QUEUE
-
setMailSender
Set the mail sender for using specific properties for sender and communication settings. -
getMailSender
MailSender getMailSender()get the mail sender -
getMailQueueItem
MailQueueItem getMailQueueItem()Returns aMailQueueItem
which could be set after sending mail- Returns:
- the
MailQueueItem
, otherwisenull
-
createMessage
Message createMessage()Creates a newMessage
object with the data of this MessageTemplate. -
getMessage
Message getMessage()Get theMessage
object of MessageTemplate instance which has been created by thesend()
method implicitly or by thecreateMessage()
method explicitly. -
setReplace
Call with true, if you want that replacements are done in subject and body. Default is false for empty MessageTemplates and true for Templates from the database.- Parameters:
b
-
-
makeReplacements
Make the replacements in subject and body.- Throws:
Exception
-
send
boolean send()Send the message. In this step, the replacements are performed and theMessage
is generated, if not already done e.g. by methodcreateMessage()
or by a previous call of thesend()
method. Depending on the kind of sending, the message is sent immediately or put into the message queue.- Returns:
true
, if mail could be sent orfalse
, if mail could not be sent or if mail has been inserted into mail queue. In all other cases an Exception is thrown.
-
getId
String getId()Get the id of the template. -
getName
String getName()Get the name of the template. -
getDescription
String getDescription()Get the description of the template. -
getApplication
Application getApplication()Returns the application of the template.- Returns:
- the application
-
getSubject
String getSubject()Get the message subject. Note, that after makeReplacements() or createMessage() is called, this method returns the replaced subject. -
getBody
String getBody()Get the message body. Note, that after makeReplacements() or createMessage() is called, this method returns the replaced body. -
getMimeType
String getMimeType()Get the mime type -
isActive
boolean isActive()Is the template active -
isLogged
boolean isLogged()Returns true if the message is logged in the mail journal -
isAddedToProcess
boolean isAddedToProcess()Returns true if the mail message is added to the process
-