Skip to content

Email Processors

When creating Inbound Email Addresses in the Vault Admin UI, Admins select an Email Processor, which defines how Vault automatically creates documents, records, and attachments from emails sent to the address. In addition to those provided by the System, you can create custom Email Processors with the Vault Java SDK. Learn more about Email to Vault in Vault Help.

An email processor is a Java class that implements the EmailProcessor interface and uses the @EmailProcessorInfo annotation. Additionally, email processors use:

  • EmailProcessorContext to retrieve an EmailItem, which represents a single email__sys record.
  • Getter methods from the EmailItem interface to retrieve source files, attachments, and field data from an email.
  • EmailService to retrieve the body of an email as HTML or plain text.
  • DocumentService to create documents.
  • RecordService to create object records.
  • Notificationservice to send notifications.

Learn more in the Javadocs.

The EmailProcessorInfo annotation defines the senders from whom the email processor will accept emails. In this example, the processor accepts emails from one or more specific groups defined in the Inbound Email Address configuration. The label element defines the value Vault displays for the processor in the Admin UI.

@EmailProcessorInfo(allowedSenders = EmailSenderType.VAULT_GROUPS, label = "Create Legal Document")

The following example creates a document using a custom document type called Email Inquiry Document, but you can use any standard or custom document type in your Vault. The processor gets an email item, then uses DocumentService to create a document and set the source file and field values. If the Allow attachments option is enabled for the specified document type, Vault automatically creates document attachments from any files attached to an email.

@EmailProcessorInfo(allowedSenders = EmailSenderType.VAULT_USERS, label = "Create Email Inquiry Document") public class EmailInquiryProcessor implements EmailProcessor { @Override public void execute(EmailProcessorContext context) { EmailItem emailItem = context.getEmailItem(); DocumentService documentService = ServiceLocator.locate(DocumentService.class); DocumentVersion documentVersion = documentService.newDocument(); documentVersion.setSourceFile(emailItem.getEmailFile()); documentVersion.setValue("name__v", emailItem.getSubject()); documentVersion.setValue("type__v", VaultCollections.asList("email_inquiry__c")); documentVersion.setValue("lifecycle__v", VaultCollections.asList("general_lifecycle__c")); documentVersion.setValue("status__v", VaultCollections.asList("draft__c")); documentService.createDocuments(VaultCollections.asList(documentVersion)); } }

Creating Object Records From Emails

Section link for Creating Object Records From Emails

The example below uses RecordService to create an object record from an email. Instead of getting the email source file, this processor first calls getEmailBodySize to ensure that the body can be loaded into memory, then uses getEmailBody() from EmailService to copy the body of the email to a Long Text field, email_body__c, as plain text. If the body exceeds 40mb (4,000,000 b), the email processor instead sets the field to an "Email body exceeds maximum size allowed" message.

@EmailProcessorInfo(allowedSenders = EmailSenderType.VAULT_USERS, label = "Create Object Record") public class ObjectEmailProcessor implements EmailProcessor { @Override public void execute(EmailProcessorContext context) { EmailItem emailItem = context.getEmailItem(); EmailService emailService = ServiceLocator.locate(EmailService.class); RecordService recordService = ServiceLocator.locate(RecordService.class); Record record = recordService.newRecord("email_to_object__c"); record.setValue("name__v", emailItem.getSubject()); record.setValue("sender__c", emailItem.getSender().getEmailAddress().getFullAddress()); int bodysize = emailItem.getEmailBodySize(EmailBodyType.TEXT_PLAIN); if (bodysize < 4000000) { record.setValue("email_body__c", emailService.getEmailBody(emailItem.getId(), EmailBodyType.TEXT_PLAIN)); } else record.setValue("email_body__c", "Email body exceeds maximum size allowed."); recordService.batchSaveRecords(VaultCollections.asList(record)).rollbackOnErrors().execute(); } }