Wednesday, 7 October 2015

Customize Email Processing in Acumatica

Hi Everyone,

You know that Acumatica CRM has ability to process incoming mails, create cases or leads, attach messages to existing contacts and so on.
Lets discuss how doe it wars and is there any ability to customize it.

First of all, to enable mail processing you should activate and configure it for your email account on "Email Accounts" screen
Acumatica Email Processing Preferences

When you have activated incoming mail processing system will automatically process all incoming emails.
There are about 14 steps of processing (do wee need to create a case? do we need to attach email somewhere? do we need to route email? ... and so on)
Some processing steps can cancel other steps. All processing are customizable: you can add new step or remove old one.

Email Processing Architecure
Lets discuss, where to find these steps and how to customize it.
To get the list of all processors, you can go to the Acumatica Site folder and find there Initialization.cs file. Default path is: "C:\Program Files (x86)\Acumatica ERP\<SiteName>\App_Code\Auxiliary\Initialization.cs"
Acumatica server folder
There you can find InitMailProcessing() function that contains all mail processing steps. System will execute all this steps one by one within provided sequence
Acumatica Mail Processors Initialization
You can easily comment these lines or add another ones, if you need to adjust standard process.
To create new processing step, you have to create new class in extension library and inherit it from base processor class. Also you have to override and implement main process method.
public class ConversationEmailProcessor : BasicEmailProcessor
{
protected override bool Process(Package package)
{
}
}

If you want to see code of existing mail processor it is also possible with customization manager. Just use search by name of the processor class.
Acumatica Customization Manager
You always can inherit your class from existing processor to change its behavior and reuse existing logic.

How does it works
From the business logic side in email subjects you have some flags, like here:
Custom Tags in Acumatica Email

Flags can be Case ID or previous Message ID. Message ID is needed to track conversation history and find previous email.
When email is processing by core logic, system will parse message subject and other attributes to find predefined flags like there.
After this, system will try to search for existing messages and cases by provided flags.
If there is a case with provided id in the system, processing will attach message to exiting case. If there is no case and you setup your system to create a new cases, system will create a new one.
The same with message, if there is a message with provided id, system will arrange it in conversation.

As described before, you always can change this logic with your own processor.

Have a nice Development!

No comments: