This example will show you how to use HarePoint Workflow Extension with a mail service, receive and process messages, and send e-mail.
Let's examine a fictional situation where employees are entering customers’ requests manually in special list on a SharePoint portal created using an "Issues" template. In our example, our goal is to automatically enter requests from customers received by e-mail into this list. In order to avoid spam, we will verify senders with the list of clients and if a sender is not listed, we will send him an auto reply with an offer to contact the company over the phone.
In order to set up an automated solution, our workflow shall download messages from a mailbox via POP3 protocol, process them, and place the results in an applications list.
SharePoint Workflow Extensions offers two activities that perform operations with e-mail via POP3 protocol: the "Receive All E-Mails to List" action and the "Receive E-Mail" action.
In terms of performance and execution time, the first method seems preferable because all child workflows will run almost simultaneously and terminate almost simultaneously. In terms of elegance and simplicity (and simplicity also means lower costs for support and maintenance), the second method is preferable, since in this case we have one workflow, and support list is not needed for its operation. But in case of large number of messages, mailbox content processing may be significantly longer than in the first case.
You should decline which method to use in your situation. In this article, we will show you both solutions. Let's start using the simple and elegant way.
Simple and elegant solution. Get the latest message and handle it
To solve the task, the workflow will run itself, which implies parallel execution of two copies of the process at some point in time. But there is a limit in SharePoint: one element - one workflow. This means that it is impossible to run multiple copies of a workflow of «Site Workflow» type, because in this type of a workflow the site is the element itself. For workflows such as «List Workflow», this restriction is less strict – you cannot run multiple copies of the process for one item simultaneously. And it is possible for different elements – we will use this issue.
You can use any element of the list to run the workflow. We can use any element other than current element to start the process. For example, to get the reference to any other element, we can use the "element whose ID is not ID of the current element” condition for the newly created item (if we create a new item in the course of the workflow), or by means of search («Find List Item» action).
This workflow will work as follows:
Let's create a workflow
1.Receive a message
Use "Receive E-Mail" action.
2.Check whether the message is received
To do this, you can check one of the required fields (“subject”).
3.Get message text
We shall assume that the message text may be in simple or in formatted form.
4.Check whether the e-mail address from which you received a message is in the customers list
5.If the address is in the customers list:
6.If the sender’s address in not in the “Clients” list:
When you start a ready workflow on any of the items in the list, it will take one message from the mailbox and process it. While the mailbox still has messages, the process will continue to restart itself until all the messages are processed.
Productive solution. Get all messages, add them to the list, process results
Before you begin creating this workflow, create a list of "Custom" (named "E-mails", for example) type with these fields for data received:
Also create a list of "Picture Library" type (nameed "Pictures", for example). It is not necessary to change the properties of this standard list.
In order to carry out the task, we divide it into two stages – mail reception and mail processing.
Create a workflow of "Site Workflow" type for the first stage.
This process will collect messages from a mailbox and enter them in the intermediate list ("E-mails", every message as an element of the list). If there are images in the html body of a message, the process will save them in the "pictures" list.
"Receive All E-Mails to List" is the main action in the workflow being created. To ensure its operation, add the "Get List Url" action to the workflow for the "e-mails" list and put the result into a variable. Get the “pictures” list link.
Then add the “Receive All E-Mails to List” action to the workflow. Specify the parameters of the connection to the server address, and the variables with lists references.
This workflow can be started manually or automatically using the free HarePoint Workflow Scheduler software.
Create a "List Workflow"-type workflow for the second stage
This process will handle incoming messages. If the e-mail address of the sender is in the list of clients, the process enters the data from the message to the application ("Issues" list). If the e-mail address of the sender is in the list of clients, the process puts the data from the message to the application ("Issues" list).
Specify the "E-mails" list when you create the workflow; enable workflow auto activation in settings when you create a workflow item in the list.
Now this workflow will be activated for a new message when it is added to the list.
1. Get the link to "Clients" list with the help of the "Get List Url" action.
2. With the help of the "Find List Item" action, select all elements from the list, including e-mail from the "FromAddress" field in "E-Mail Address" field of the current record.
3. Get the number of such records with the help of "Get Array Items Count" action.
4. Create an entry in the "Issues" list if there is at least one such entry ("If any value equals value" condition),
Some mailing systems send formatted text only, some systems duplicate message text in plain text. Check the string in order to avoid loss of the message owing to differences in mailing services operation:
Use the "Create List Item at Url" action to create a new item. You will get the URL for the parameter using the "Get list URL" action. Set necessary fields in INI format within the “specified values” parameter.
5. Then copy attachments from current item into a new one. To do that, use the “Copy List Item Attachments To List Item” action.
6. If there are no such entries send the message.
Thus, we have two workflows automating the entry of new requests received by e-mail upon the completion of all those actions. The ready workflows look as follows:
After starting the first collecting process, all the messages from the mailbox will be placed into the «E-mails» intermediate list.
The second process handles each new item. If the message was sent from a known address, the process creates a new item in the «Issues» list.
HarePoint Workflow Extensions provide a complete set of tools to work with mailing services. Standard tools provide message sending only.
With HarePoint Workflow Extensions it is possible to receive the mail, send e-mails with attachments (from a file, an element, or URL), and automates many tasks associated with receiption and sorting of messages, automatic response generation, and correspondence record-keeping.