This SharePoint 2013 tutorial, we will explore how to read an email in Outlook and add the content of the email body to a SharePoint List in SharePoint 2013. We can achieve this by writing a C# console application using Microsoft Exchange Web Services.
If we talk about a requirement, let’s take a part of an HR Portal in which an HR sends some information about newly joined employees to, let’s say, admin team via an E-mail. Then, the admin team stores the information of each employee in the SharePoint List manually.
We are writing a console application here where every email with Employee details will be creating an item in the SharePoint List and the fields of the item will be obtained from the email body. Make sure, the format of the email body is structured as demonstrated below in the last image.
The console application can be scheduled via Windows Scheduler to run every 5 minutes to check the incoming emails in Outlook.
Read Outlook Emails and Add Email Content in SharePoint List
Please follow the below steps for more detailed information.
Prerequisites:
Make sure that you have Microsoft Exchange Web Services installed and running. If you do not have Exchange Web Services, you might get an error during compilation.
using Microsoft.Exchange.WebServices.Data;
using MEWS=Microsoft.Exchange.WebServices.Data;
Follow the below steps for installation:
Once you have created a console application and added all the required references, right-click on References and click “Manage NuGet Packages…“
It will open the NuGet Package Manager. Search for “Microsoft.Exchange.WebServices” and when found, select those and click Install.
Create the object of the Exchange Service and provide your Exchange Service credentials. Link your Mailbox with the Exchange Service Object.
ExchangeService oews = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
Credentials = new WebCredentials("akashkumhar","password123","domainname")
}; oews.AutodiscoverUrl("[email protected]");
Here, I have created two folders under Inbox – LetterBox, and SuccessfulItems.
- LetterBox – It contains all the Emails which are to be parsed and processed.
- SuccessfulItems – It contains all the Emails for which the corresponding items are created successfully in the SharePoint List.
The application is designed in such a way that when you send an email to the linked Exchange Email ID, the Inbox rule moves the email received with subject “EmailReader” to the LetterBox so, that the intended emails are only parsed by the code and not the emails in the Inbox.
The console application reads all the unread emails from LetterBox, creates the items in SharePoint list, and moves them to Successful Items.
Make sure the email body is standard for all the emails, as shown below.
I have created an Employee list with the below columns and data types for demonstration.
The LetterBox is parsed for all the unread emails and the data is picked from the Email body to be added into the corresponding columns.
I have done a successful implementation of this functionality. Check the below-created list items.
If I go ahead and show you the “Edit” form of one item, you could see how the field values are correctly placed at their respective fields.
You may like following SharePoint list tutorials:
- Create and Manage Task List in SharePoint
- Create an organization chart from a list in SharePoint Online/2013/2016 using JavaScript
- Change column ordering in list forms in SharePoint Online/2013/2016
- How to remove/hide default title column from SharePoint Online list (modern/Classic)
- Create a Survey in SharePoint Online or SharePoint 2013/2016/2019
- Different ways to hide/disable quick edit in a list in SharePoint 2013/2016/Online
- Copy list items from one list to another in SharePoint programmatically using CSOM
- User Information List in SharePoint 2016/2013/2010
- How to display more than 3 views in SharePoint 2013/2016/Online list or document library
- How to configure email in Outlook 2013
When you deal with a “Choice” column which is a Checkbox with multiple option values, then you need to handle it differently than other columns. This will consider each option separated by commas as different and mark the checkboxes correctly.
I am Akash Kumhar a SharePoint Consultant.