{"id":246,"date":"2012-01-17T14:42:43","date_gmt":"2012-01-17T14:42:43","guid":{"rendered":"https:\/\/www.harepoint.com\/Blog\/?p=246"},"modified":"2019-03-22T11:40:09","modified_gmt":"2019-03-22T11:40:09","slug":"email-with-sharepoint-workflow","status":"publish","type":"post","link":"https:\/\/www.harepoint.com\/Blog\/email-with-sharepoint-workflow\/","title":{"rendered":"Receive and process messages, and send e-mail with SharePoint Workflow"},"content":{"rendered":"\n<ul>\n<li><a href=\"#latest\">Handling the latest message<\/a>\n<li><a href=\"#creation\">Workflow creation<\/a>\n<li><a href=\"#all\">All messages processing<\/a>\n<li><a href=\"#conclusion\">Conclusion<\/a>\n<\/ul>\n<p>This example will show you how to use HarePoint Workflow Extension with mail service, receive and process messages, and\u00a0send e-mail.<\/p>\n<p>Let&#39;s examine a fictional situation where employees are entering customers\u2019 requests manually in a special list on a SharePoint portal created using an\u00a0&quot;Issues&quot; 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\u00a0the list of clients and if a sender is not listed, we will send him an auto-reply with an offer\u00a0to contact the company over the phone.<\/p>\n<p>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.<\/p>\n<p>SharePoint Workflow Extensions offers two activities that perform\u00a0operations with\u00a0e-mail via POP3 protocol: the\u00a0<b>&quot;Receive All E-Mails to List&quot; action<\/b> and the\u00a0<b>&quot;Receive E-Mail&quot; action<\/b>.<\/p>\n<ul>\n<li><b>&quot;Receive All E-Mails to List&quot; <\/b>loads all messages from a mailbox into a specified SharePoint list. Using a\u00a0workflow\u00a0which automatically activates when an item is added to the list, you can handle all e-mail messages. Thus, in order to build the\u00a0solution, we need two workflows and a message\u00a0sublist: one process will load messages to\u00a0the list with the &quot;Receive All E-Mails to List&quot; action; the second workflow will contain the message processing instructions, and a separate copy for each message will be activated.<\/li>\n<li><b>&quot;Receive E-Mail&quot; <\/b>loads only the last message from a mailbox, passing\u00a0its parts to the workflow`s variables. Therefore, recursion shall be used in order to process all messages in a mailbox: if the &quot;Receive E-Mail&quot; uploads a message from a mailbox, then, in the end, the workflow activates itself in order to get and process next message. In this case, we can solve the problem using a single workflow.<\/li>\n<\/ul>\n<p>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 a large number of messages, mailbox content processing may be\u00a0significantly longer than in the first case.<\/p>\n<p>You should decline\u00a0which method\u00a0to use in your situation. In this article, we will show you both solutions. Let&#39;s start using the\u00a0simple and elegant way.<\/p>\n\n<table border=\"1\" cellpadding=\"5\" style=\"border-style: solid; border-collapse: collapse; border-spacing: 0px;\"><tbody><tr><td rowspan=\"2\"><b>Component name and type<\/b><\/td>\n<td align=\"center\" colspan=\"2\"><b>Set of Workflow components<\/b><\/td><\/tr>\n<tr><td align=\"center\"><b>SharePoint Workflow<\/b><\/td>\n<td align=\"center\"><b>HarePoint Workflow Extensions<\/b><\/td><\/tr>\n<tr><td>Get List URL (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Get List URL\"\/><\/td><\/tr>\n<tr><td>Find List Item (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Find List Item\"\/><\/td><\/tr>\n<tr><td>Get Array Items Count (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Get Array Items Count\"\/><\/td><\/tr>\n<tr><td>If any value equals value (Condition)<\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"If any value equals value\"\/><\/td>\n<td><\/td><\/tr>\n<tr><td>Create List Item at URL (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Create List Item at URL\"\/><\/td><\/tr>\n<tr><td>Get E-Mail Property (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Get E-Mail Property\"\/><\/td><\/tr>\n<tr><td>Receive E-Mail (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Receive E-Mail\"\/><\/td><\/tr>\n<tr><td>Receive All E-Mails to List (action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Receive All E-Mails to List\"\/><\/td><\/tr>\n<tr><td>Save E-Mail Attachments (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Save E-Mail Attachments\"\/><\/td><\/tr>\n<tr><td>Start Workflow (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Start Workflow\"\/><\/td><\/tr>\n<tr><td>Get Array Item (Action)<\/td>\n<td><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Get Array Item\"\/><\/td><\/tr>\n<tr><td>Send an E-mail (Action)<\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/yes.gif\" alt=\"Send an E-mail\"\/><\/td>\n<td><\/td><\/tr>\n<\/tbody><\/table>\n\n<a name=\"latest\"><\/a>\n<h2>Simple and elegant solution. Get the latest message and handle it<\/h2>\n\n<p>To solve the task, the workflow will run itself, which implies parallel execution of two copies of the process at\u00a0some point in time. But\u00a0there is a limit in SharePoint: one element &#8211; one workflow. This\u00a0means that it is impossible to run multiple copies of a\u00a0workflow of \u00abSite Workflow\u00bb type because in this type of workflow the site is the element itself. For workflows such as \u00abList Workflow\u00bb, this restriction is less strict\u00a0\u2013 you cannot run multiple copies of the process for one item simultaneously. And it is possible for different elements \u2013 we will use this issue.<\/p>\n<p>You can use any element of the list to run the workflow. We can use any element other than the current element to start the process. For example, to get the reference to any other element,\u00a0we can use the\u00a0&quot;element whose ID is not ID of the current element\u201d condition for the newly created item (if we create a new item in the course of the workflow), or by means of search (<b>\u00abFind List Item\u00bb action<\/b>).<\/p>\n<p>This workflow will work as follows:<\/p>\n<ul>\n<li>Get the latest unread email from a server<\/li>\n<li>If the message is received and if it is sent from known address \u2013 create a new item in an\u00a0\u00abIssues\u00bb list. Run a\u00a0new instance of the workflow for this list item<\/li>\n<li>If the message is received from an unknown address \u2013 create a new item in the \u00abe-mails\u00bb list and send a reply message to the contact, then start another copy of the\u00a0workflow for any other item in the list<\/li>\n<li>Complete operation.<\/li>\n<\/ul>\n\n<a name=\"creation\"><\/a>\n<h2>Let&#8217;s create a workflow<\/h2>\n<p><i>1.Receive a message<\/i><\/p>\n<p>Use &quot;Receive E-Mail&quot; action.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-1.png\"\/><\/p>\n\n<p><i>2.Check whether the message is received<\/i><\/p>\n<p>To do this, you can check one of the required fields (\u201csubject\u201d).<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-2.png\"\/><\/p>\n<p><i>3.Get message text<\/i><\/p>\n<p>We shall assume\u00a0that the message\u00a0text may\u00a0be in simple or\u00a0in formatted form.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-3.png\"\/><\/p>\n<p><i>4.Check whether the\u00a0email address from which you received a message is in the customers list<\/i><\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-4.png\"\/><\/p>\n\n<p><i>5.If the address is in the customers list:<\/i><\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-5.png\"\/><\/p>\n\n<ul>\n<li><i>Get sender\u2019s name<\/i><\/li>\n<li><i>Create an element in the \u201cIssues\u201d list<\/i>\n\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-6.png\"\/><\/p><\/li>\n<li><i>Save all attachments from the message<\/i>\n<br\/>You can also select attachments to save using a filter. E.g., you can use \u201c*.jpg;*.doc;*.docx;*.pdf\u201d filter, which will save JPG images and DOC, DOCX, and PDF documents.<\/li>\n<li><i>Start workflow copy for the\u00a0new element<\/i><\/li>\n<\/ul>\n\n<p><i>6.If the sender\u2019s address in not in the \u201cClients\u201d list:<\/i><\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-7.png\"\/><\/p>\n\n<ul>\n<li><i>Send a response message with contact request<\/i>\n\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-8.png\"\/><\/p><\/li>\n<li><i>Find another element in the list (with ID, other than current one) and run a copy of the\u00a0workflow for it<\/i>\n<br\/>This action is necessary because SharePoint cannot run two copies of a\u00a0process for a\u00a0single item.<\/li>\n<\/ul>\n<p>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\u00a0restart itself until\u00a0all the messages are\u00a0processed.<\/p>\n\n<a name=\"all\"><\/a>\n<h2>Productive solution. Get all messages, add them to the list, process results<\/h2>\n<p>Before you begin creating this\u00a0workflow, create a list of &quot;Custom&quot; (named &quot;E-mails&quot;, for example)\u00a0type with\u00a0these fields for data\u00a0received:\n\n<\/p>\n<table class=\"zebra-striped\">\n<thead><tr><th>Column<\/th>\n<th>Data Type<\/th>\n<th>Received data<\/th><\/tr><\/thead>\n<tbody><tr><td><b>Title<\/b><\/td>\n<td>Single line of text<\/td>\n<td>Subject<\/td><\/tr>\n<tr><td><b>Description<\/b><\/td>\n<td>Multiple lines of text \/ enhanced rich text<\/td>\n<td>Html Body<\/td><\/tr>\n<tr><td><b>FromName<\/b><\/td>\n<td>Single line of text<\/td>\n<td>Sender display name<\/td><\/tr>\n<tr><td><b>FromAddress<\/b><\/td>\n<td>Single line of text<\/td>\n<td>Sender e-mail address<\/td><\/tr>\n<tr><td><b>FromUser<\/b><\/td>\n<td>Person or Group<\/td>\n<td>SPUser object, if there is a user with same e-mail address on the site<\/td><\/tr>\n<tr><td><b>Date<\/b><\/td>\n<td>Date and Time<\/td>\n<td>Date Sent<\/td><\/tr>\n<tr><td><b>TextBody<\/b><\/td>\n<td>Multiple lines of text<\/td>\n<td>Message text as plain text<\/td><\/tr>\n<tr><td><b>ReplyToString<\/b><\/td>\n<td>Single line of text<\/td>\n<td>\u201cReplyTo\u201d<\/td><\/tr>\n<\/tbody><\/table>\n\n<p>Also create a list of &quot;Picture Library&quot; type (nameed &quot;Pictures&quot;, for example). It is not necessary to change the properties of this standard list.<\/p>\n<p><b>In order to carry out the task, we divide it into two stages \u2013 mail reception and mail processing.<\/b><\/p>\n<p><b><i>Create a\u00a0workflow of &quot;Site Workflow&quot; type for the first stage.<\/i><\/b><\/p>\n<p>This process will collect messages from a mailbox and enter them in the intermediate list (&quot;E-mails&quot;, every message as an element of the list). If there are images in the\u00a0html body of a message, the process will save them in the &quot;pictures&quot; list.<\/p>\n<p><b>&quot;Receive All E-Mails to List&quot;<\/b> is the main action in the workflow being created. To ensure its operation, add the &quot;Get List Url&quot; action to the workflow for the &quot;e-mails&quot; list and put the result into a variable. Get the \u201cpictures\u201d list link.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-9.png\"\/><\/p>\n<p>Then add the\u00a0<b>\u201cReceive All E-Mails to List\u201d action<\/b> to the workflow. Specify the parameters of the connection to the server address, and the variables with lists references.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-10.png\"\/><\/p>\n\n<p>This workflow can be started manually or automatically using the free <a href=\"\/Products\/HarePointWorkflowScheduler\/Default.aspx\">HarePoint Workflow Scheduler<\/a> software.<\/p>\n<p><b>Create a &quot;List Workflow&quot;-type workflow for the second stage<\/b><\/p>\n<p>This process will handle incoming messages. If the\u00a0e-mail address of the sender is in the list of clients, the process enters the data from the message to the application (&quot;Issues&quot; 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 (&quot;Issues&quot; list).<\/p>\n<p>Workflow procedure:<\/p>\n<ul>\n<li>Check\u00a0e-mail addresses in the &quot;Clients&quot; list<\/li>\n<li>If the\u00a0e-mail address exists in the &quot;Clients&quot; list, create\u00a0an entry in &quot;Issues&quot; list<\/li>\n<li>If the\u00a0e-mail address does not exist in the &quot;Clients&quot; list,\u00a0send\u00a0response e-mail message with the message text quote and contact request.<\/li>\n<\/ul>\n\n<p>Specify the &quot;E-mails&quot; list when you create the\u00a0workflow; enable workflow auto activation in settings when you create a workflow item in the list.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-11.png\"\/><\/p>\n<p>Now this workflow will be activated for a new message when it is\u00a0added to the list.<\/p>\n<p>1. Get the link to &quot;Clients&quot; list with the help of the\u00a0<b>&quot;Get List Url&quot; action<\/b>.<\/p>\n<p>2. With the help of the\u00a0<b>&quot;Find List Item&quot; action<\/b>, select all elements from the list, including\u00a0e-mail from the &quot;FromAddress&quot; field in &quot;E-Mail Address&quot; field of the current record.<\/p>\n<p>3. Get the number\u00a0of such records with the help of <b>&quot;Get Array Items Count&quot; action<\/b>.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-12.png\"\/><\/p>\n\n<p>4. Create an entry in the &quot;Issues&quot; list if there is at least one such entry (<b>&quot;If any value equals value&quot; condition<\/b>),<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-13.png\"\/><\/p>\n\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-14.png\"\/><\/p>\n<p>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\u00a0differences in mailing services operation:<\/p>\n<ul>\n<li>If the field with formatted text (Description) is not empty use it to enter the applications text.<\/li>\n<li>If the field is empty, we shall use plain text (TextBody). The result is placed into \u00abtext\u00bb variable.<\/li>\n<\/ul>\n<p>Use the\u00a0<b>&quot;Create List Item at Url&quot; action<\/b> to create a new item. You will get the\u00a0URL for the parameter using the\u00a0<b>&quot;Get list URL&quot; action<\/b>. Set necessary fields in INI format within the\u00a0\u201cspecified values\u201d parameter.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-15.png\"\/><\/p>\n<p>5.\u00a0Then copy attachments from current item into a new one. To do that, use the <b>\u201cCopy List Item Attachments To List Item\u201d action<\/b>.<\/p>\n<p>6. If there are no such entries send the message.<\/p>\n\n<p>\n    <a href=\"\/Pictures\/Workflow\/Example-E-Mail-16.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-16.png\"\/><\/a>\n<\/p>\n\n<p>Thus, we have two workflows automating the entry of new requests received by e-mail upon the\u00a0completion of all those actions. The ready workflows look as follows:<\/p>\n<p><b>Mail collector<\/b><\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-17.png\"\/><\/p>\n\n<p><b>Mail processor<\/b><\/p>\n<p>\n    <a href=\"\/Pictures\/Workflow\/Example-E-Mail-18.png\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-18.png\"\/><\/a>\n<\/p>\n<p>After starting the first collecting process, all the messages from the mailbox will be placed\u00a0into the \u00abE-mails\u00bb intermediate list.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-19.png\"\/><\/p>\n\n<p>The second process handles each new item. If the message was sent from a\u00a0known address, the process creates a\u00a0new item in the \u00abIssues\u00bb list.<\/p>\n<p><img decoding=\"async\" src=\"\/Pictures\/Workflow\/Example-E-Mail-20.png\"\/><\/p>\n\n<a name=\"conclusion\"><\/a>\n<h2>Conclusion<\/h2>\n<p><a href=\"\/Products\/HarePointWorkflowExtensions\/Default.aspx\">HarePoint Workflow Extensions<\/a> provide a\u00a0complete set of tools to work with mailing services. Standard tools provide message sending only.<\/p>\n<p>With HarePoint Workflow Extensions it is possible to receive the mail, send emails with attachments (from a file, an element, or URL), and\u00a0automates many tasks associated with receiving and sorting of messages, automatic response\u00a0generation, and\u00a0correspondence record-keeping.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example will show you how to use HarePoint Workflow Extension working with the mail service, receive and process messages, send e-mail.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[14,25],"_links":{"self":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts\/246"}],"collection":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/comments?post=246"}],"version-history":[{"count":4,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":972,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/posts\/246\/revisions\/972"}],"wp:attachment":[{"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/media?parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/categories?post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.harepoint.com\/Blog\/wp-json\/wp\/v2\/tags?post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}