Class Mail
- All Implemented Interfaces:
Displayable
,StringFiller
,HasId
- Author:
- Syam
-
Field Summary
Fields inherited from class com.storedobject.core.StoredObject
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
alert
(Transaction transaction, String message, StoredObject person) Sends an alert for the given transaction with a specified message and person information.static void
alert
(Transaction transaction, String message, StoredObject person, String subject) Sends an alert with the specified details.static void
alert
(Transaction transaction, String message, Iterable<? extends StoredObject> persons) Sends an alert with a specified message to a group of persons in the context of a given transaction.static void
alert
(Transaction transaction, String message, Iterable<? extends StoredObject> persons, String subject) Sends an alert email to the specified recipients with the provided message and subject.boolean
attach
(TransactionManager tm, ContentProducer... content) Attaches one or more content items to the mail using the provided transaction manager.boolean
attach
(TransactionManager tm, FileData... files) Attaches the provided files to the specified transaction manager.boolean
attach
(TransactionManager tm, Iterable<FileData> files) Attaches a collection of files to the current object using the provided TransactionManager.boolean
attachFrom
(TransactionManager tm, Mail another) Attach attachments from another mail.static void
Adds the necessary columns for the Mail table.static Mail
Creates an alert and returns it as a Mail object.static Mail
Creates and prepares an alert mail based on the provided TransactionManager instance.static boolean
customizeMetadata
(String fieldName, UIFieldMetadata md) Customizes the metadata for a specified field name by applying specific configurations.Retrieves the "CC address" associated with the mail.Retrieves the error value associated with the current object's error property.static String
getErrorValue
(int value) Retrieves a specific error value from the predefined error values array based on the provided input value.static String[]
Retrieves the array of error values associated with the mail.Retrieves the "from address" associated with the sender of the mail.Retrieves the message type associated with this mail.Retrieves the "reply-to address" associated with the mail.Retrieves the sender associated with the mail.Retrieves the SenderGroup instance associated with the current senderGroupId.Retrieves the identifier of the sender group associated with the mail.Retrieves the identifier of the sender associated with the mail.Retrieves the subject of the mail.Retrieves the "to address" associated with the mail.static void
Defines and adds various index configurations for a mail table.static String[]
links()
Provides links to associated classes or objects related to 'Mail'.void
setCCAddress
(Id personId) Set the "CC address".void
setCCAddress
(StoredObject person) Set the "CC address".void
setCCAddress
(String ccAddress) Set "CC address".void
setErrorValue
(String errorValue) Sets the error value for the Mail instance.void
setMessageType
(String messageType) Sets the message type for the mail.void
setReplyToAddress
(String replyToAddress) Sets the "Reply-To" address for the email.void
Sets the sender for the mail using the specified sender ID.void
Sets the sender for the mail instance using the providedSender
object.void
setSender
(BigDecimal idValue) Sets the sender information for the mail using the provided identifier value.void
setSenderGroup
(Id senderGroupId) Sets the sender group for the mail.void
setSenderGroup
(SenderGroup senderGroup) Sets the sender group for the mail.void
setSenderGroup
(String senderGroupName) Sets the sender group for the mail based on the given sender group name.void
setSenderGroup
(BigDecimal idValue) Sets the sender group using the given identifier value.void
Sets the recipient of the message.void
setSubject
(String subject) Sets the subject of the mail.void
setToAddress
(Id personId) Set the "to address".void
setToAddress
(StoredObject person) Set the "to address".void
setToAddress
(String toAddress) Set "to address".toString()
String representation of the instance.void
This will be invoked by the system whenever the object is saved to the DB.Methods inherited from class com.storedobject.core.Message
getCreatedAt, getError, getMessage, getMessageID, getSent, getSentAt, getSentTo, getSentToId, protectedColumns, ready, sent, sent, setCreatedAt, setError, setMessage, setMessageID, setSent, setSentAt, setSentTo, setSentTo
Methods inherited from class com.storedobject.core.StoredObject
addLink, addLink, addLink, addLink, addLink, addLink, addLink, addLink, checkCurrency, checkCurrency, checkForDuplicate, checkForDuplicate, checkTimeZone, checkTransaction, clearObjectLinks, contemporary, copy, copy, count, count, count, count, count, count, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, create, created, delete, delete, delete, deleted, directUpdate, equals, exists, exists, exists, exists, exists, existsFileData, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsMaster, existsMaster, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, family, family, family, fill, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getAttachment, getAttachmentId, getChildren, getDeleted, getDeleted, getExistsCondition, getExistsCondition, getFileData, getFileData, getHistorical, getId, getKeyIndex, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getNotExistsCondition, getNotExistsCondition, getParent, getParent, getParent, getParentId, getParentId, getParentId, getRelated, getRelated, getTransaction, getTransactionId, getTransactionIP, getUnique, getUniqueCondition, hashCode, inserted, isModified, isVirtual, list, list, list, list, list, list, list, list, list, list, list, list, list, listFileData, listFileData, listHistory, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listTree, listTree, listTree, listTree, listViaQuery, listViaQuery, load, load, load, load, loaded, loading, makeNew, makeVirtual, migrate, moduleName, nextVersion, objectLink, objectLink, objectLink, objectLinks, objectLinks, old, person, previousVersion, previousVersion, query, query, query, query, query, query, query, query, query, query, query, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, reload, reload, reloaded, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeReverseLinks, removeReverseLinks, save, save, save, save, save, save, save, save, save, save, save, save, save, save, saved, saving, setMaster, setRawValue, setTransaction, stringify, tableName, timestamp, toCode, toDisplay, transacting, undelete, undelete, undeleted, updated, user, userId, validate, validateChildAttach, validateChildDetach, validateChildUpdate, validateDelete, validateInsert, validateParentAttach, validateParentDetach, validateParentUpdate, validateUndelete, validateUpdate, valueEquals
-
Constructor Details
-
Mail
public Mail()Initializes a new instance of the Mail class with default settings. This constructor sets the initial error status to 3.
-
-
Method Details
-
columns
Adds the necessary columns for the Mail table.- Parameters:
columns
- The Columns object used to define the column structure. This method adds the following columns:- "SenderGroup" with type "Id" - "ToAddress" with type "text" - "CCAddress" with type "text" - "ReplyToAddress" with type "text" - "Subject" with type "text" - "MessageType" with type "text" - "Sender" with type "Id"
-
indices
-
links
Provides links to associated classes or objects related to 'Mail'.- Returns:
- An array of strings, each representing a link in the format: "Label|QualifiedClassName|AdditionalInfo|". Example elements: "Attachments|com.storedobject.mail.Attachment||", "Errors|com.storedobject.mail.Error||".
-
customizeMetadata
Customizes the metadata for a specified field name by applying specific configurations.- Parameters:
fieldName
- the name of the field whose metadata needs to be customizedmd
- the UIFieldMetadata object that represents the metadata of the field- Returns:
- true if the metadata was successfully customized for the specified field, false otherwise
-
setSenderGroup
Sets the sender group for the mail based on the given sender group name. This method retrieves theSenderGroup
object associated with the specified name and updates the sender group for the mail.- Parameters:
senderGroupName
- the name of the sender group to be set
-
setSenderGroup
Sets the sender group for the mail.- Parameters:
senderGroupId
- The ID of the sender group to be set.
-
setSenderGroup
Sets the sender group using the given identifier value.- Parameters:
idValue
- The identifier value of the sender group.
-
setSenderGroup
Sets the sender group for the mail.- Parameters:
senderGroup
- The sender group to be set. If null, the sender group ID is set to null.
-
getSenderGroupId
Retrieves the identifier of the sender group associated with the mail.- Returns:
- The identifier of the sender group as an
Id
.
-
getSenderGroup
Retrieves the SenderGroup instance associated with the current senderGroupId.- Returns:
- The SenderGroup instance corresponding to senderGroupId, or null if it is not found.
-
getFromAddress
Retrieves the "from address" associated with the sender of the mail. If the sender is not defined, an empty string will be returned.- Returns:
- The "from address" as a
String
, or an empty string if the sender is not set.
-
setToAddress
Set "to address". Comma delimited email addresses.- Parameters:
toAddress
- Addresses.
-
setToAddress
Set the "to address".- Parameters:
personId
- Id of thePerson
,SystemUser
,SystemUserGroup
,Contact
,PersonRole
orMessageGroup
.
-
setToAddress
Set the "to address".- Parameters:
person
-Person
,SystemUser
,SystemUserGroup
,Contact
,PersonRole
orMessageGroup
.
-
getToAddress
Retrieves the "to address" associated with the mail.- Returns:
- The "to address" as a String. This typically contains comma-separated email addresses.
-
setCCAddress
Set "CC address". Comma delimited email addresses.- Parameters:
ccAddress
- Addresses.
-
setCCAddress
Set the "CC address".- Parameters:
personId
- Id of thePerson
,SystemUser
,SystemUserGroup
,Contact
,PersonRole
orMessageGroup
.
-
setCCAddress
Set the "CC address".- Parameters:
person
-Person
,SystemUser
,SystemUserGroup
,Contact
,PersonRole
orMessageGroup
.
-
getCCAddress
-
setReplyToAddress
Sets the "Reply-To" address for the email. This address specifies where replies to the email should be sent.- Parameters:
replyToAddress
- The "Reply-To" email address to be set. Typically, this is a valid email address in string format.
-
getReplyToAddress
Retrieves the "reply-to address" associated with the mail. This value may be used to indicate the address that should receive replies to the mail if different from the "from address".- Returns:
- The "reply-to address" as a String, or null if not set.
-
setSubject
Sets the subject of the mail.- Parameters:
subject
- The subject of the mail as a string.
-
getSubject
Retrieves the subject of the mail.- Returns:
- The subject of the mail as a String.
-
setMessageType
Sets the message type for the mail.- Parameters:
messageType
- The type of the message to be set.
-
getMessageType
Retrieves the message type associated with this mail.- Returns:
- The message type as a String.
-
setErrorValue
Sets the error value for the Mail instance. The method determines the error code corresponding to the specified error value from the predefined errorValues array. If the provided error value is not found, a default error code is assigned.- Parameters:
errorValue
- The error description string to set as the current error value. This string is compared against the elements in the errorValues array.
-
getErrorValues
Retrieves the array of error values associated with the mail.- Returns:
- An array of strings representing error values.
-
getErrorValue
Retrieves a specific error value from the predefined error values array based on the provided input value.- Parameters:
value
- the input value used to determine the appropriate error value. This value is used as an index after being adjusted by the length of the error values array.- Returns:
- the error value as a String corresponding to the adjusted index derived from the input value.
-
getErrorValue
Retrieves the error value associated with the current object's error property.- Returns:
- The error value as a String, derived from the error property.
-
setSender
Sets the sender for the mail using the specified sender ID.- Parameters:
senderId
- The identifier of the sender to be set.
-
setSender
Sets the sender information for the mail using the provided identifier value. The identifier value is wrapped into anId
object and assigned to the sender.- Parameters:
idValue
- The identifier value of the sender as aBigDecimal
.
-
setSender
-
getSenderId
-
getSender
-
toString
Description copied from class:StoredObject
String representation of the instance. Mostly used for logging purposes.- Overrides:
toString
in classStoredObject
- Returns:
- String representation of the instance.
-
validateData
Description copied from class:StoredObject
This will be invoked by the system whenever the object is saved to the DB. It will be invoked in all cases, while creating new objects and updating/deleting/un-deleting existing objects. If any exception is raised by this method, the process of saving to the DB will be abandoned.
Note: This method is mainly used to validate the data of all attributes of the object, and it may be used by others for validating the object. For example, front-end data-entry systems can use this method for validating the object.
- Overrides:
validateData
in classMessage
- Parameters:
tm
- Current transaction manager.- Throws:
Exception
- If data is invalid.
-
attach
Attaches one or more content items to the mail using the provided transaction manager. This method saves the current context if not already saved, processes the content, and creates attachments by linking the content to mail.- Parameters:
tm
- the transaction manager used to handle database transactionscontent
- one or more content producers that generate the content to be attached- Returns:
- true if the attachment process is successful, false otherwise
-
attach
Attaches the provided files to the specified transaction manager.- Parameters:
tm
- the transaction manager to which the files should be attachedfiles
- the array of file data objects to be attached- Returns:
- true if the files were successfully attached, false otherwise
-
attach
Attaches a collection of files to the current object using the provided TransactionManager.- Parameters:
tm
- the TransactionManager to handle the transactional operationsfiles
- an Iterable collection of FileData objects to be attached- Returns:
- true if the files were successfully attached; false otherwise
-
attachFrom
Attach attachments from another mail. When doing this, the actual contents are not duplicated. Instead, they are linked internally.- Parameters:
tm
- Transaction manageranother
- Another mail.- Returns:
- True if successful.
-
createAlert
Creates an alert and returns it as a Mail object. This method may throw an SOException in case of errors during the alert creation process.- Returns:
- A Mail object representing the created alert.
- Throws:
SOException
- If an error occurs during the alert creation process.
-
createAlert
Creates and prepares an alert mail based on the provided TransactionManager instance. If no sender group with the name "Alert" exists, it attempts to create and save one using the transaction manager. The sender group ID is then assigned to the mail. If no TransactionManager is provided or the sender group creation fails, the method throws an SOException.- Parameters:
tm
- the TransactionManager instance used to handle database transactions for creating a new sender group if required. It can be null.- Returns:
- a Mail object initialized with sender group details for the alert.
- Throws:
SOException
- if no sender groups are defined for mail alerts, and the sender group creation fails or cannot be performed.
-
alert
public static void alert(Transaction transaction, String message, StoredObject person) throws Exception Sends an alert for the given transaction with a specified message and person information.Note: The person object could be an instance of
Person
,SystemUser
,HasContacts
orContact
.- Parameters:
transaction
- the transaction object associated with the alertmessage
- the message to be included in the alertperson
- the person object related to the alert- Throws:
Exception
- if an error occurs while processing the alert
-
alert
public static void alert(Transaction transaction, String message, Iterable<? extends StoredObject> persons) throws Exception Sends an alert with a specified message to a group of persons in the context of a given transaction.Note: The person iterator could contain instances of
Person
,SystemUser
,HasContacts
orContact
.- Parameters:
transaction
- The transaction within which the alert is being generated.message
- The message content for the alert.persons
- An iterable collection of recipients (StoredObject instances) to whom the alert is sent.- Throws:
Exception
- If an error occurs while processing the alert.
-
alert
public static void alert(Transaction transaction, String message, StoredObject person, String subject) throws Exception Sends an alert with the specified details.Note: The person object could be an instance of
Person
,SystemUser
,HasContacts
orContact
.- Parameters:
transaction
- The transaction context in which the alert will be executed.message
- The message content of the alert.person
- The stored object representing the person to whom the alert is related.subject
- The subject of the alert.- Throws:
Exception
- If an error occurs while sending the alert.
-
alert
public static void alert(Transaction transaction, String message, Iterable<? extends StoredObject> persons, String subject) throws Exception Sends an alert email to the specified recipients with the provided message and subject.Note: The person object could be an instance of
Person
,SystemUser
,HasContacts
orContact
.- Parameters:
transaction
- The transaction object used to save the email alert.message
- The message content of the alert email.persons
- An iterable collection of recipients represented as StoredObject instances.subject
- The subject line of the alert email. If null, the default subject "Alert" is used.- Throws:
Exception
- If an error occurs during alert creation, email preparation, or saving the alert.
-
setSentTo
-