List all mail enabled document libraries

Published on Tuesday, 17 October 2023

How to list all mail enabled document libraries in SharePoint

Whether a given document library is "email enabled", or not, is defined by the SPList.EmailAlias property. This property contains only the "alias" e.g. "mycoollist" and not the full email address. To get the full address one must check the SPIncomingEmailService.ServerDisplayAddress.

A simple script to list all libraries that can receive mails (including the corresponding address) looks like this:


#requires -pssnapin Microsoft.SharePoint.PowerShell
<#
  .SYNOPSIS
	Lists all mail enabled Lists

  .EXAMPLE
	.\Get-SPMailEnablesLists.ps1 -Site https://mysite.mysharepoint.local/
	Lists all email enabled lists in all webs of site https://mysite.mysharepoint.local/
#>

[CmdletBinding()]
param(
	[Parameter(ParameterSetName="WebApp", Mandatory=$true)]
    [string]$WebApp,
	[Parameter(ParameterSetName="Site", Mandatory=$true)]
    [string]$Site,
    [Parameter(ParameterSetName="Web", Mandatory=$true)]
    [string]$Web
)

$webs = @()

if(![string]::isNullOrEmpty($web)) {
    $webs += Get-SPWeb $Web
}

if(![string]::isNullOrEmpty($site)) {
    Get-SPWeb -Site $Site -Limit all | % {
        $webs += $_
    }
}

if(![string]::isNullOrEmpty($WebApp)) {
    Get-SPSite -WebApplication $WebApp -Limit All | % {
        Get-SPWeb -Site $_ -Limit all | % {
            $webs += $_
        }
    }
}


$mailDomain = ""

$srv = Get-SPServiceInstance | ? { $_.GetType().Name -eq "SPIncomingEmailServiceInstance" } | select -first 1
if($srv -eq $null) {
    Write-Warning "No incoming mail ServiceInstance found in the Farm!"
} else {
    if(-not $srv.Service.Enabled) {
        Write-Warning "incoming mail is disabled!"
    }
    $mailDomain = "@$($srv.Service.ServerDisplayAddress)"
}


$webs | % {
    $w = $_
    Write-Verbose "Processing $($_.Url)"
    $_.Lists | % {
        $l = $_
        if([string]::isNullOrEmpty($l.EmailAlias)) {
            return;
        }
        $x = [pscustomobject]@{
            List = $l.Title;
            Site = $w.Url;
            Alias = $l.EmailAlias;
            FullMail = $l.EmailAlias+$mailDomain
        }
        write-output $x
    }
}