Thursday, January 21, 2016

Fix List Incoming Email Settings after SharePoint Migration

During a SharePoint Migration from 2010 to 2013 of a customer, we have seen that incoming email no longer worked as expected.
So I tried to reset via UI incoming email settings for a specific List and we saw that the service is come back to work.
The following PowerShell script do the same thing I've done through SharePoint UI but works across all lists of a specific web application.
Every properties of incoming email setting of a list are stored into Propertie Bag of the RootFolder of the list.
These settings are preserved even if we disable incoming email alias setting it to $null.

$SPWebApp = Get-SPWebApplication "http://webappurl"

foreach ($SPsite in $SPwebApp.Sites)
{
   foreach($SPweb in $SPsite.AllWebs)
  {
     foreach ($SPList in $SPweb.Lists)
     {
         if ( ($splist.CanReceiveEmail) -and ($SPlist.EmailAlias) )
         {
             #save email alias
             $emailAlias = $SPList.EmailAlias
             #disable incoming email
             $SPList.EmailAlias = $null
             $splist.Update()
             #re-enable incoming email
             $SPList.EmailAlias = $emailAlias
             $splist.Update()
         }
     }
  }
}


These are all the properties for incoming email settings at List level you can set/check:

  • vti_emailsaveoriginal
  • vti_emailattachmentfolders
  • vti_emailusesecurity
  • vti_emailoverwrite
  • vti_emailsavemeetings