SharePoint 2013 Incoming Email Issue : Emails disappear


 

Introduction

The other day we had a SharePoint 2013 development environment which had been configured up to receive email into libraries.

The configuration had been working for a while with no problems, there are issues with the incoming email on older versions of SharePoint 2013 but this farm was patched to May 2015.

We used the following Technet article to configure incoming email: https://technet.microsoft.com/en-us/library/cc262947.aspx

Unfortunately, email was never getting into SharePoint. The service had been working without any problems for a few weeks.

 

Problem Analysis

 

On investigation of the problem showed that email was successfully routed via Exchange to the SharePoint server via the locally installed SMTP service. The email was arriving successfully into the drop folder and after a few minutes the email disappeared. However, it would never appear in the document library! The email just disappeared.

Another symptom of the problem was seen when accessing the document library settings page for Incoming Email. Not all the settings would be loaded, the page was missing a large set of settings.

Normally the page looks like this :-

incoming-email-settings-library-ok

 

However, it was only showing this information :-

incoming-email-settings-library-broken

 

When someone attempted to make a change to the email settings for the list then the following error would be thrown:-


Server Error in '/' Application.

Error in the application.Description: An unhandled exception occurred during the execution of the current web request. 

Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Microsoft.SharePoint.SPException: Error in the application.

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: [SPException: Error in the application.]   
Microsoft.SharePoint.SPList.UpdateDirectoryManagementService(String oldAlias, String newAlias) +1239   
Microsoft.SharePoint.SPList.Update(Boolean bFromMigration) +311   
Microsoft.SharePoint.ApplicationPages.EmailSettingsPage.SubmitButton_Click(Object sender, EventArgs args) +1347   
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +146   
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3586

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248

 

Strange behaviour indeed!

I fired up ULSViewer (http://www.microsoft.com/en-us/download/details.aspx?id=44020) on the offending server. Whilst watching the ULS log, another email was sent to the document library. After a minute or so a message popped up.

Cannot load type EWSSharePointEventReceiver from Assembly: [Assembly Name].

So for some reason the assembly could not be loaded, hmm so why is that?
I had a look through the GAC and could find the assembly name. However, using a .Net Reflector such as Just Decompile (http://www.telerik.com/products/decompiler.aspx) or .NET Reflector (http://www.red-gate.com/products/dotnet-development/reflector/). I could see that the class was not in the assembly. Speaking with the developers, I found out the class names had been changed. So the next thing I checked was the event receivers.

With a bit of PowerShell, I found a set of event receivers which were being fired by the item email received event.

I removed the event receiver using the following PowerShell and running it in the SharePoint 2013 PowerShell Management Shell:-

 


$eventReceiverName="EWSSharePointEventReceiver*";
$siteUrl="https://sharepoint";
$site = Get-SPSite $siteUrl;
$rootWeb = $site.RootWeb;
$allWebs = $rootWeb.AllWebs();

foreach($checkList in $allListsInWeb)        
{   
	Write-Host "Checking List: " $checkList.Title " for event receiver class: " $eventReceiverName;
	$eventReceivers = $checkList.EventReceivers | ?{$_.Class -like $eventReceiverName};            
 
        If($eventReceivers -ne $null -and $eventReceivers.Count -gt 0)
        {                   
             foreach($removeReceiver in $eventReceivers)                        
             {                       
	           Write-Host "Removing Event Receiver: $removeReceiver";
		   $removeReceiver.Delete();
             }
 
             $checkList.Update();
        }
}

 

After the corrupt event receivers were removed from the list then resending the email to SharePoint worked! Now the email appeared in the document library.

SharePoint 2013/Online Attachment Viewer Enhancement


Introduction

Update: 22nd January 2016 – Further updates to fix an issue with Minimal Download Strategy (MDS) and works correctly when used in multiple list view app parts on the same page.

Recently I had a client that wanted a better way to get to the attachments that were linked to a SharePoint list item from a list view web part. This request had me thinking and I didn’t think it would be too difficult to achieve using SharePoint 2013’s Client Side Rendering (CSR) user interface components. Anyway one night I decided on an approach and put the following together. attachment-viewer-example

Solution

The solution uses client-side rendering to override the output that the field displays in a list view. This is achieved using a list template override to change the Attachment’s field rendering. The solution makes use of the SharePoint Callout Manager which is used to display links to the attachment. I found a set of articles which have been posted in the Resources section below really good for getting to grips with using the Callout Manager. The implementation works on both SharePoint 2013 and SharePoint Online. The one issue with the approach is that you have to reference the JavaScript file for each view, so if you create a new view then that view needs to be setup. This isn’t a problem if you are creating a custom list with a schema.xml as you can reference the JavaScript in the list’s schema. The solution makes use of the SharePoint 2013 JSOM API and the list of attachments is only created one the user has clicked on the paperclip icon to see the list of attachments. This is to try and keep the load down on the server when there are lots of attachments for a particular list item.

Resources

The following websites provided a great resource in getting the Callout Manager and SharePoint JSOM working. http://blog.alexboev.com/2012/07/custom-callouts-in-sharepoint-2013.html

http://www.learningsharepoint.com/2013/05/09/sharepoint-2013-callout-popup-tutorial/

SharePoint 2013 – Custom CallOut with File Preview – Obilogic

http://msdn.microsoft.com/en-us/library/office/dn268594(v=office.15).aspx

Setup

Watch the video showing you how to setup the attachment viewer.

To take advantage of the list attachment viewer and set it up for a particular list view, do the following:

  • Download the zipfile, found at the bottom of the post
  • Unzip the zip file to extract the ITSP.SP.AttachmentField.js file.
  • Upload the ITSP.SP.AttachmentField.js into a suitable location, I would suggest the Site Assets library.
    • Create a folder called Scripts within the Site Assets library
    • Upload the ITSP.SP.AttachmentField.js into this folder, this keeps your content organised.
    • Alternatively, you could package up the JS file to deploy the files by using a Module into a site collection.
  • Browse to the SharePoint list that you wish to enable the viewer on.
    • Make sure that the list has the Attachment field showing as this is the column that is going to be overridden
  • Click “Edit Page”

attachment-viewer-stepone-editpage

  • Click on the List Viewer Web Part, choose Edit Web Part

attachment-viewer-steptwo-editwebpart

  • The web part properties will appear on the right hand side
  • Expand the miscellaneous section
  • In the JSLink field type in the location of the ITSP.SP.AttachmentField.js file
  • E.g ~site/SiteAssets/Scripts/ITSP.SP.AttachmentField.js
  • Use the ~site token to substitute for the local site url

attachment-viewer-stepthree-jslink

  • Click Apply
  • Click Ok
  • Save the Page

Now create a list item and add some attachments to it. When you click on the paperclip icon you will get a callout which will display all the attachments for that list item. attachment-viewer-paperclip attachment-viewer-example Please let me know if you find it useful, I have tested the script with 5/6 attachments, it should scale with 20 or so documents as the list of documents is built each time you click on a particular document.

Update 21st May 2014

An updated version of the script has been released to add support for the Minimal Download Strategy feature. This helps to reduce the number of bytes being downloaded to the client. For more information, please read this MSDN Blog Post.

The behaviour that you would start seeing is that the attachment callout would appear once and then never again. More information can be found here:

Update 17th November 2015

An updated version of the script has been released to add support for being used in multiple list view app parts on the same page.
Please use this version instead.

Thanks to Dar for reporting this issue.

Update 4th January 2016

I did not do enough testing. An issue was discovered by Ken. This is related to when having multiple list view web parts on the page.

Update 22nd January 2016

There still seemed to be an issue with MDS and the control was polluting the global JavaScript pool, this update fixed those has been tested on SharePoint Online.

Download:
ITSP.SP.AttachmentField-20160122.zip