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:
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:
3. This is how you check the mailbox:
Validate the passcode (key), you can make your own key here:
You might need this callback function if you get an SSL certificate error:
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:
To reject the task:
To mark the task as complete:
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):
This is the send email function, if you need it:
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.