Package com.veeva.vault.sdk.api.email
package com.veeva.vault.sdk.api.email
This package provides interfaces to create documents and content based on emails sent to Vault. Your Vault must also
be configured by an Admin to process emails. Learn more about configuring
Email to Vault in Vault Help.
Email Processor
An email processor is a Java class that implements theEmailProcessor interface and has the
EmailProcessorInfo annotation.
Email processors take data from emails and convert it into document, object record, or attachment field values and content. Email processors use:
EmailProcessorContextto retrieve anEmailItem, which represents a singleemail__sysrecord.EmailServiceto retrieve the body of an email as HTML or plain text.DocumentServiceto create documents.RecordServiceto create object records.
Example Email Processor: Create Document from Email Attachments
The example email processor below creates a document from email attachments. If no attachments are found, the processor creates a document from the email's.eml file instead.
This example code demonstrates the use of the entire Email SDK package to access email metadata and content.
@EmailProcessorInfo(
label = "Create Document from Email Attachments",
allowedSenders = {EmailSenderType.VAULT_USERS_AND_PERSONS}
)
public class CreateDocumentFromEmailProcessor implements EmailProcessor {
@Override
public void execute(EmailProcessorContext context) {
// Get the main email object from the context
EmailItem emailItem = context.getEmailItem();
// Use the EmailService to get the plain text body
EmailService emailService = ServiceLocator.locate(EmailService.class);
String body = emailService.getEmailBody(emailItem.getId(), EmailBodyType.TEXT_PLAIN);
// Get sender and recipient details
EmailSender sender = emailItem.getSender();
EmailRecipient recipient = emailItem.getRecipient();
EmailAddress senderAddress = sender.getEmailAddress();
LogService logService = ServiceLocator.locate(LogService.class);
logService.info("Processing email from {} with subject {}", senderAddress.getDisplayName(), emailItem.getSubject());
// Get all attachments from the email
List<EmailFileReference> attachments = emailItem.getEmailAttachments();
DocumentService documentService = ServiceLocator.locate(DocumentService.class);
List<DocumentVersion> docsToCreate = VaultCollections.newList();
if (attachments.isEmpty()) {
// If no attachments, create a document from the .eml file itself
logService.debug("No attachments found. Creating document from .eml file.");
EmailFileReference emlFile = emailItem.getEmailFile();
DocumentVersion docVersion = documentService.newDocument();
docVersion.setSourceFile(emlFile);
docVersion.setValue("name__v", emailItem.getSubject());
docVersion.setValue("type__v", VaultCollections.asList("undefined__v"));
docVersion.setValue("lifecycle__v", VaultCollections.asList("unclassified__v"));
docVersion.setValue("status__v", VaultCollections.asList("unclassified__v"));
docVersion.setValue("description__v", "Created from email .eml file.");
docsToCreate.add(docVersion);
} else {
// If there are attachments, create one document for each
logService.debug("Found {} attachments. Creating documents.", attachments.size());
for (EmailFileReference attachment : attachments) {
DocumentVersion docVersion = documentService.newDocument();
docVersion.setSourceFile(attachment);
docVersion.setValue("name__v", attachment.getFileName());
docVersion.setValue("type__v", VaultCollections.asList("undefined__v"));
docVersion.setValue("lifecycle__v", VaultCollections.asList("unclassified__v"));
docVersion.setValue("status__v", VaultCollections.asList("unclassified__v"));
docVersion.setValue("description__v", "Created from email attachment.");
docsToCreate.add(docVersion);
}
}
if (!docsToCreate.isEmpty()) {
documentService.createDocuments(docsToCreate);
}
}
}
-
ClassDescriptionProvides a structured representation of a single email address, parsed from a header such as
To,From, orCc.Specifies a type of email body content, such as HTML or plain text.A reference to a file sourced from an inbound email, such as the.emlfile itself or an attachment.Represents a single inbound email and provides access to its content and metadata.Defines the entry point for a custom email processor.Provides contextual information for the execution of anEmailProcessor.Indicates a class is a custom email processor.Represents the recipient of an inbound email, which corresponds to a configured Inbound Email Address record in Vault.Represents the sender of an inbound email, providing access to their Vault identity and raw email address.Defines the set of allowed senders for anEmailProcessor.A service for retrieving the content of emails that have been received by Vault.