Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

After migration from SharePoint 2007 to 2010 the list feature to receive emails is not working on migrated sites. The functionality is enabled in the UI and when I´m checking $list.CanReceiveEmail with Powershell.

When I´m disabling and enabling the functionality it´s fixed for the list. Now my plan is to write a Powershell script to disable and enable the the receive email setting.

How can I disable and enable the feature with PowerShell? CanReceiveEmail is a ReadOnly property...

$list.CanReceiveEmail = $false "CanReceiveEmail" is a ReadOnly property.

$WA = Get-SPWebApplication https://sharepoint  

$Sites = $WA.Sites

foreach($Site in $Sites)
{
       foreach($web in $site.AllWebs){
            $lists = $web.lists
                foreach($list in $lists){                   
                    if (($list.CanReceiveEmail -eq $true) -AND ($list.EmailAlias -ne $Null)){
                    Write-Host($list.Title +" ; "+$list.EmailAlias +" ; "+ $list.ParentWeb.Url)
                    #$list.CanReceiveEmail = $false   
                    #Error    
                    #$list.Update()
                    #$list.CanReceiveEmail = $true
                    #$list.Update()  

                    }
                }
        }         
}
share|improve this question
add comment

2 Answers

I don't know of any ready to go scriptlet that would do that, so you are basically stuck with the SharePoint object model. Based on that, I had a look at the UI page that manages that setting. From the EmailSettings.aspx page in the layout folder it would seems that the logic is situated in the code behind class EmailSettingsPage from the Microsoft.SharePoint.ApplicationPages assembly. That said, you can open the page with reflector and have a look at the code, particularly at the Submit button handler.

 if ((this.TxtAlias.Text == null) || (this.TxtAlias.Text.Length == 0))
 {
     throw new SPException(SPResource.GetString("MissingEmailAlias", new object[0]));
 }
 this.m_List.EmailAlias = this.TxtAlias.Text;
 this.m_RootFolder.Properties["vti_emailusesecurity"] = this.UseSecurityTrue.Checked ? 1 : 0;
 if (this.ShowSaveAttachments)
 {
     this.m_RootFolder.Properties["vti_emailsaveattachments"] = 
              this.SaveAttachmentsTrue.Checked ? 1 : 0;
 }
 if (this.ShowSaveOriginalAndMeetings)
 {
     this.m_RootFolder.Properties["vti_emailsavemeetings"] = 
          this.MeetingsTrue.Checked ? 1 : 0;
     this.m_RootFolder.Properties["vti_emailsaveoriginal"] = 
          this.SaveOriginalTrue.Checked ? 1 : 0;
 }
 if (this.ShowAttachmentFolders)
 {
    this.m_RootFolder.Properties["vti_emailoverwrite"] = this.OverwriteTrue.Checked ? 1 : 0;
    if (this.AttachmentFoldersSender.Checked)
    {
        this.m_RootFolder.Properties["vti_emailattachmentfolders"] = "sender";
    }
    else if (this.AttachmentFoldersSubject.Checked)
    {
        this.m_RootFolder.Properties["vti_emailattachmentfolders"] = "subject";
    }
    else
    {
        this.m_RootFolder.Properties["vti_emailattachmentfolders"] = "root";
    }
 }
 if (this.ShowAutoApprove)
 {
     this.m_RootFolder.Properties["vti_emailautoapprove"] = 
         this.AutoApproveTrue.Checked ? 1 : 0;
 }

Based on this, it would seem that you need to set some properties on the root folder of the list. This may also explain you problem: maybe some of the properties were changed between SP 2007 and 2010 or something broke in the upgrade? Anyway, there is also a line that invoke targetList.ResetContentTypes() so you can give it a go.

If I can give you a suggestion, you should try to check if any of the above property shows some sign of corruption. Only resort to manually replicate the above code if you have to.

share|improve this answer
add comment

LaPhi,

Whether a list can receive email, and thus whether the CanReceiveEmail is true or false, is based on a number of factors, but doesn't actually affect whether a list can receive email. Think of it as a flag determining whether the list is set up properly to receive email, not a setting you can turn on and off.

To change the state of email reception in a list, you need to know a bit more about how email handling works for lists. I wrote about his in Building the SharePoint User Experience, chapter 6, and I think you can read the section related to email enabling lists here:

http://books.google.no/books?id=5fe62gzRl18C&pg=PT125&lpg=PT125&dq=building+the+sharepoint+user+experience+Can+Receive+Email&source=bl&ots=5hmB0vELnD&sig=WsCHXMFFiOMz4PMvsTEOL_tNl3M&hl=en&sa=X&ei=kVFDUb_YJonCtAb_uoGYBg&redir_esc=y

.b

share|improve this answer
    
Many thanks Bjorn! Awesome! –  LaPhi Mar 15 '13 at 17:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.