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.

Thoughts? Comments about this post? Please leave them here..

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s