Help is available by sending an email to csf-support@mit.edu
Have any suggestion on how improve this wiki? Please give us your feedback at csf-support@mit.edu
Need to know the configurable properties for csf-email? Go to The project .properties file properties for more information.
Quick Links to:
1. Introduction
The CSF Email Service is a module in CSF to handle various functions related to sending emails to a single or group of recipients.
The implementation will include all the methods in the existing EmailServiceImpl in CSF common-legacy. New methods are added
to handle the bulk email and email preview functionality. In addition, new functionalities have been added to store the email message
created in the database and to retrieve the email queue status/statistics via service methods. The EmailServiceImpl is not annotated
so it has to be configured in one of the application Context files in the web application. It is not annotated so we can inject the
ApplicationConfiguration for those web applications that are using sais-common.
2. Dependencies
2.1 CSF base
We will utilize CSF base module to obtain the application configuration information.
2.2 CSF test
We will utilize CSF test module to facilitate the unit tests created for the email module
2.3 CSF orm
We will utilize CSF orm module to facilitate the IO operations of its dao.
3. Object Model
3.1 Class Diagram
The following domain classes are created to represent
(1) EmailModel is created to hold all the fields in an email message. It is used by other web application
to pass data of the email to be sent to the EmailService.
The following diagram represents the domain class EmailModel.
(2) EmailEvent is a persistent object created to represent the persist object for each email that is queued or sent.
Besides from address, to address, the cc and bcc list, it will also hold the full email text (i.e. content after
translating the velocity template), a status (queued or sent), create date and a reference to the EmailAttachment
persistent object if the email sent has attachment(s).
(3) EmailAttachment is a persistent object created to save the attachment associated with email events.
The following diagram represents the domain class EmailEvent and EmailAttachment and their relationship:
3.2 Class Description.
3.2.1 EmailModel
This is the domain class that represents an Email Message object. It contains the following fields:
- emailFrom – the email address of the sender
- emailSubject – the subject of the email
- emailTos – the list of email addresses of those who will be sent a copy of the email
- emailCC – the list of email addresses of those will get a cc copy of the email.
- emailBcc – the list of email addresses of those will get a bcc copy of the email.
- emailReportRecipient – the list of email addresses of those who will get a copy of the summary report.
- emailText – the content of the email.
3.2.2 EmailPerson
This is the domain class that represents an Email Person object. It contains the following fields:
- emailAddress -- the email address of the person
- personName -- the full name of the person with the email address
3.2.3 EmailEvent
This is the domain class that represents the persisted Email Event object. It contains the following fields:
- emailFrom -- the email address of the sender.
- emailTo – the recipient of the email
- emailSubject – the subject of the email
- emailCcs -- a comma-separated list of email address that will be sent a cc copy of the email
- emailBccs -- a comma-separated list of email address that will be sent a bcc copy of the email
- emailText -- the content of the email
- html -- whether the email is in plain text or html text
- statusFlag -- the status (Queued or Sent) of the email in the queue
- createDate -- the date when the email was created
- createBy -- the user who create the email
- attachments -- set of attachment(s) that are associated with this email
- appId -- the id of the application that creates the email
3.2.4 EmailAttachment
This is the domain class that represents the persisted Email Attachment object. It contains the
following fields:
- seqNo -- the order of the email attachment.
- document -- the byte array that stores the content of the attachment
- filename -- the file name of the attachment file
- mimeType -- the mime type of the attachment
- emailEvents -- the list of email events associated with this attachment
4. Service Modules
4.1 Class Diagram
4.2 Class Descriptions.
4.2.1 EmailCentralService Interface
This is the interface that defines the methods available for the other web applications to utilize when they are required
to send out emails to a single or a list of recipients. The service includes the following methods:
- public void sendBulkEmail(EmailModel emailModel, String summaryReportTemplate, boolean defaultSort)
- public void sendBulkEmailWithTemplate(EmailModel emailModel, String velocityTemplate, Map context, String summaryReportTemplate, boolean defaultSort)
- public Map<String, Integer> sendBulkEmailWithCounts(EmailModel emailModel)
- public Map<String, Object> generateEmailPreviewWithTemplate(EmailModel emailModel, String type, String velocityTemplate, Map context)
- public Map<String, Object> generateSummaryReportPreview(EmailModel emailModel)
- public void sendEmailWithAttachments(EmailModel emailModel, List<File> attachments)
- public void sendEmailWithTemplateAndAttachments(EmailModel emailModel, String velocityTemplate, Map context, List<File> attachments)
- public void sendEmailWithAttachmentsFromDataSource(EmailModel emailModel, List<File> attachments, boolean useApplicationConfig)
- public void newEmail(String velocityTemplate, Map context, String to, String from, String subject, boolean html)
<span style="color: #000091">public</span> <span style="color: #910091">void</span> newEmail(String velocityTemplate, Map context, String[] tos, String from, String subject, boolean html)
- public void newEmail(String velocityTemplate, Map context, String to, String subject, boolean html)
- public void
newEmail(String velocityTemplate, Map context, String[] tos, String subject, boolean html)
- public void newEmail(String body, String to, String subject, boolean html)
<span style="color: #000091">public</span> <span style="color: #910091">void</span> newEmail(String from, List<EmailPerson) to, String subject, String body, String[] cc, String[] bcc, String[] rr, String velocityTemplate)
<span style="color: #000091">public</span> <span style="color: #910091">void</span> newEmail(String body, String[] tos, String from, String subject, String[] cc, String[] bcc, boolean html, List<File> attachments)
<span style="color: #000091">public</span> <span style="color: #910091">void</span> newEmail(String body, String from, String[] tos, String subject, String[] cc, String[] bcc, boolean html, List<DataSource> attachments, boolean overrideFromAddress)
<span style="color: #000091">public</span> <span style="color: #910091">void</span> newEmail(String from, String[] to, String subject, String body, String[] cc, String[] bcc, String[] rr)
- public List getMessageQueue()
- public void batchSend()
- public boolean validateEmailAddress(String emailAddress)
- public List getMessageQueue()
- public List<String Object> getMessageQueueStatistics(Date fromDate, Date thruDate, String emailFrom, String emailTo, String status)
- public void batchSend()
- public void delete()
- public boolean validateEmailAddress(String emailAddress)
4.2.3 EmailCentralService Implementation
This is the implementation class for the EmailCentralService. It contains an EmailService object (in csf common-legacy module) to
perform its tasks.
4.2.3.1 sendBulkEmail
This method obtains an EmailModelDomain Object. It will then process the data and call the newEmail method to save the email and
the summary report for the intended recipients. The call to the newEmail method should be configured with the following parameters:
newEmail(String from, String[] to, String subject, String body, String[] cc, String[] bcc, String[] rr);
The following attributes in the EmailModel Object will affect the generation of email:
- a list of email addresses of the recipients specified in the "To" field <required>
- a list of email addresses of the recipients specified in the "cc" field <optional>
- a list of email addresses of the recipients specified in the "Bcc" field <optional>
- a list of email addresses of the recipients speicified in the "Report Recipient" field <optional>
- email subject<optional>
- email text <required>
4.2.3.2 sendBulkEmailWithTemplate
This method obtains an EmailModel Object, a velocity template name and a map that contains the values for the variables in the template.
It will use the velocity template and the map to generate the text for the email. Then, it will call the sendBulkEmail method to create
and save the email message and the summary report for intended recipients.
4.2.3.3 sendBulkEmailWithCounts
This method obtains an EmailModel Object. It will call the sendBulkEmail method to create and save the email message and the summary
report to intended recipients. Then, it will call the BatchSend to send out the email and return the counts of successful and failed delivery.
4.2.3.4 generateEmailPreviewWithTemplate
This method obtains an EmailModel Object, a string to specify the type of preview, a velocity template name, and a Map that contains the values
for the variables within the velocity template. It will use the velocity template and the map to generate the text for the email. Then, it will
updated the email tect to the email model object and put the updated object into the returned Map. If a summary report preview is required, it
will call the generateSummaryReportPreview method to add the attributes necessary to generate the summary report preview to the returned map.
4.2.3.5 generateSummaryReportPreview
This private method adds the objects/attributes necessary to create a preview of the summary report. The objects to be added are as follows:
- A String that contains the content of the summary report
4.2.3.6 sendEmailWithAttachments
This method accepts an EmailModel object and a list of attachments. It will then call newEmail method to create and save the message(s) in database.
4.2.3.7 sendEmailWithTemplateAndAttachments
This method accepts an EmailModel object, a velocity template name, a map of replaced values, and a list of File objects (attachments). It will then
merge the velocity template with the replace values. Afterwards, it will call sendEmailWithAttachments to create and save the message(s) in database.
4.2.3.8 sendEmailWithAttachmentsFromDataSource
This method accepts an EmailModel object and a list of DataSource objects(attachments) and a boolean to signal the system to use the from
address in the applicationConfiguration or not. It will then call newEmail method to create and save the message(s) in database
4.2.3.9 newEmail
These sets of methods are the same public methods available in the EmailService in the CSF common-legacy module.
4.2.3.10 sendReportRecipientEmail
4.2.3.11 createReportRecipientContent
This method is a public method migrated over from the EmailServiceImpl in common-legacy module.
4.2.3.12 saveMessage
4.2.3.13 saveMessageWithAttachmentAsDataSource
4.2.3.14 updateDataToEmailEvent
4.2.3.15 updateApplicationConfigurationParametersToEmailEvent
4.2.3.16 updateMessageContent
4.2.3.17 createMimeMessagePreparatorForEmailWithCcBccAttachments
4.2.3.18 createMimeMessagePreparatorForEmail
4.2.3.19 prepare
4.2.3.20 batchSend
This method is a public method migrated over from the EmailServiceImpl in common-legacy module.
4.2.3.21 sendMessage
These methods are public methods that are migrated over from the EmailServiceImpl in common-legacy module.
4.2.3.22 getMessageQueue
This method is a public method migrated over from the EmailServiceImpl in common-legacy module.
4.2.3.23 getMessageQueueStatistics
4.2.3.24 validateEmailAddress
This method takes an input of email address in String and validate if the email address is valid. If the email address is valid, it will return
true. If not, it will return false. The input email address is validated according to the following conditions:
- The system will create a new InternetAddress object using the input email address and then invoke the validate method of the InternetAddress object to verify it is a real email address