Saving an email message as a document

PolicyCenter does not store email objects created through the gw.api.email.Email class in the database. However, it is possible to save the contents, recipient information, and other information of an email as a document in the configured DMS application.

Because all variations of the gw.api.email.EmailUtil.sendEmailWithBody methods take all of the sending information explicitly, you can save the email information by using the following process in Gosu code:

  1. Create the email subject and body and determine recipients.
  2. Send the email by calling one of the sendEmailWithBody methods.
  3. If PolicyCenter does not encounter an exception, create a document recording the details of the sent email.

Example code

For a simple example of the code needed to save an email as a document, refer to the either the BillingCenter or ClaimCenter CreateEmailScreen.pcf PCF file. To see the example, select the highest level element, then open the Code tab at the bottom of the screen.
If desired, it is possible to replicate this functionality in Gosu code using the sample code as the basis for your code. Possible improvements to the example code include the following:
  • Adding a header to the document with metadata to determine the docContainer object.
  • Adding a BCC to archive email addresses.
  • Creating a batch process that fetches the emails in a specific account and stores any outgoing email as a document.
It is important to understand that the sample code in the CreateEmailScreen.pcf PCF file performs a transaction bundle commit. In most cases, you do not need to perform the bundle commit in your code:
  • If calling the code from a Gosu rule, the rule is already in a commit bundle.
  • If calling the code from workflow, the workflow is already in a transaction bundle.
  • If calling the code from a work queue, the workqueue is mostly likely already in a transaction bundle.