Complete SharePoint tasks via Email using Exchange Web Services (Microsoft Exchange Web Services Managed API 2.0)

Sometimes it is a pain that you want to complete a SharePoint task but you are not on your company’s network or connected via VPN.

This blog shows you how you can send an email to a mailbox to complete a SharePoint task.

How it will works:

1. SharePoint assigns a task to you and you receive a task notification email;

2. There will be several links in that email, e.g., Approve, Reject, Complete task, etc… You can click one of the links and it will open a new email window with a subject like this:

[Action]**SPEmail**[Task ID]**[Passcode]**[Site URL]**[Task List GUID]**[Task Title]

3. You should not change the email subject but you can put your comments in the email body, which will become the task comments;

4. Click the “send” button and the email will be sent to a specific email address, which is monitored by a SharePoint timer job. The timber job will check this mail box every 5 minutes for new emails.

  • The SharePoint timer job will check if the subject contains the word “**SPEmail**”
  • then complete the task for you if the Passcode is correct.

How to make it work:

1. Create the task email in SharePoint designer and generate the “Approve via Email” or “Reject via Email” link:

2015-06-24 09_30_29-Define E-mail Message


2015-06-24 09_31_30-Define E-mail Message

2. Download and install Microsoft Exchange Web Services Managed API 2.0 to your development machine and then add reference to “Microsoft.Exchange.WebServices” (e.g., Browse to “C:\Bin\EwsAPI\Microsoft.Exchange.WebServices.dll”).

Add the following at the top of your code:

2015-06-24 09_51_51-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

3. This is how you check the mailbox:

2015-06-24 09_57_10-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

2015-06-24 10_27_20

Validate the passcode (key), you can make your own key here:

2015-06-24 10_30_18

You might need this callback function if you get an SSL certificate error:

2015-06-24 10_19_42-Oracle VM VirtualBox

4. Complete the SharePoint task:

According to the [Action] in the email subject line, you will need to complete the task for the user.

To approve the task:

2015-06-24 10_35_12 Approve

To reject the task:

2015-06-24 10_35_12 Reject

To mark the task as complete:

2015-06-24 10_35_12 MarkComplete

Finally, add this line:


After you have complete the task, don’t forget the delete the email (move it to the “Deleted Items” folder):


And this is the AlterTask function (in case of workflow is locked for some reason, it will try again):

2015-06-24 10_39_00-AlterTaskFunction

This is the send email function, if you need it:

2015-06-24 10_40_58-sendemailfunctin

You can write a timer job to run this every 5 minutes.


Before you deploy this to your production server, you will need to copy the “Microsoft.Exchange.WebServices.dll” file from your dev machine to the same location in the production server. You might also need to put it into the GAC folder in the production server.

This entry was posted in EWS, SharePoint 2010, SharePoint Designer 2010, Visual Studio 2010, Web Service and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s