CTK Email Parser SDK Methods

For advanced use cases, CTK Email parser now exposes Apex classes and methods, to allow developers to utilize email parsing capabilities within their custom solutions.

Class : EmailConverter

Static Method : Messaging.InboundEmail convertFromDocument(ID documentID)

Converts document (ID of Attachment or ContentDocument) to instance of Messaging.InboundEmail

Static Method : convertFromDocumentAsync(List lstDocIds, Callable callback)

Converts list of document (ID of Attachment or ContentDocument) to instance of Messaging.InboundEmail.

Note:

  1. If convertFromDocumentAsync method is invoked in asynchronous mode (for example, from a batch class, or future method); then only first document will be parsed

Sample Code

The following sample code creates a custom trigger on ContentVersion. When a new document is inserted, it is asynchronously sent for email parsing along with a callable Apex class instance as a callback.

Developers can implement the call method in the Callable implementation class to further process the converted email message.

// Code for Trigger to invoke file parsing
trigger TempContentVersionTrigger2 on ContentVersion (after insert) {
    if(Trigger.isAfter && Trigger.isInsert){
        ContentVersion cv = Trigger.new[0]; // take only first item
        Callable callback = new TempCallable();  // instance of a callback handler class
        ctkemailparser.EmailConverter.convertFromDocumentAsync(new List<ID> { cv.ContentDocumentId }, callback);
    }
}


// Callable Apex class - for callback handling, post email parsing
public with sharing class TempCallable implements System.Callable{

    public Object call(String str, Map<String, Object> args) {

        Messaging.InboundEmail eml = (Messaging.InboundEmail) args.get('EMAIL');

        ID cvID = (ID) args.get('DOCUMENTID');

        // Additional code as per business logic
    }
}