locked
How to find out which list is associated with specific incoming email address RRS feed

  • Question

  • Hey Guys,

    I've a received a request today from a user asking me which list was setup with a specific incoming email address.

    Is there a way to find out which list is associated with an email address?

    Thanks

    Friday, May 30, 2014 8:00 AM

Answers

  • OK, here's the latest and final version that works with subsites

    Usage : Get-EmailEnabledList.ps1 -SiteCollection https://abc... -EmailAddressName xyz

    <#
    
    .SYNOPSIS
        The script cycles through all sites and subsites inside the defined side collection and lists which library is configured with the specified email address
        
    .PARAMETER
        Get-EmailEnabledList -siteCollection <sitecollectionURL> -EmailAddress <emailAddress>
        Note that <emailAddress> is the part before the '@domain.com'
        
    .NOTES
        30 May 2014
        Thomas MALLIE
    
    #>
    
    Param(
    [string]$SiteCollection,
    [string]$EmailAddressName
    )
    
    # Load SharePoint module if not done yet
    if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {Add-PSSnapin Microsoft.SharePoint.PowerShell;}
    cls
    
    $SPSite = Get-SPSite $SiteCollection
    foreach ($website in $SPSite.AllWebs)
        {
            foreach ($list in $website.Lists)
                {
                if ($list.CanReceiveEmail -eq $true)
                    {
                    if ($list.EmailAlias -eq $EmailAddressName)
                       {
                       Write-Host ""
                       Write-Host "The email belongs to list $list in $website" -ForegroundColor green
                       Write-Host "Email       : $EmailAddress@domain.com"
                       Write-Host "Website URL :" $website.Url
                       Write-Host "List URL    :" $list.Url
                       Write-Host ""
                       Exit
    
                       }
                     }
                }
        }
    Write-Host "Not found"



    • Marked as answer by Fluidetom Friday, May 30, 2014 2:02 PM
    • Edited by Fluidetom Friday, May 30, 2014 2:04 PM
    Friday, May 30, 2014 2:00 PM

All replies

  • OK after a bit of research I found a way to achieve this.

    I simply looked up the email address in ADUC, then did a search in SP with the display name. I could locate the list and manually confirm it was configured with the incoming email address I was looking for.

    I also found the below script on Stackoverflow, but got "The 'using' keyword is not supported in this version of the language." when I tried to run it. Any idea how to fix that? I'd like to have a script to link a library to an email address istead of the manual approach described above.

    http://stackoverflow.com/questions/4974110/sharepoint-how-do-i-find-a-mail-enabled-list-if-i-only-have-the-email

    $SiteCollection = ""
    $EmailAddress = "" # only the part before the @
    
    # Load SharePoint module if not done yet
    if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {Add-PSSnapin Microsoft.SharePoint.PowerShell;}
    cls
    
    # # #
    using System;
    using Microsoft.SharePoint;
    
    namespace FindListByEmail
    {
        class Program
        {a
            static void Main(string[] args)
            {
                string siteUrl = $SiteCollection;
                string email = $EmailAddress; 
    
                using (SPSite site = new SPSite(siteUrl))
                {
                    foreach (SPWeb web in site.AllWebs)
                    {
                        try
                        {
                            foreach (SPList list in web.Lists)
                            {
                                if (list.CanReceiveEmail)
                                {
                                    if (list.EmailAlias != null && list.EmailAlias.Equals(email, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        Console.WriteLine("The email belongs to list {0} in web {1}", list.Title, web.Url);
                                        Console.ReadLine();
                                        return;
                                    }
                                }
                            }
                        }
                        finally
                        {
                            if (web != null)
                            {
                                web.Dispose();
                            }
                        }
                    }
                }
            }
        }
    }

    Friday, May 30, 2014 8:27 AM
  • You can check the following properties of SPlist:

    CanReceiveEmail

    EmailAlias

    EnableAssignToEmail

    Friday, May 30, 2014 8:29 AM
  • I've come up with this script, but I miss a part to cycle through subsites if there's any.

    Would anyone know how to add that to my script?

    Param(
    [string]$SiteCollection,
    [string]$EmailAddressName
    )
    
    # Load SharePoint module if not done yet
    if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {Add-PSSnapin Microsoft.SharePoint.PowerShell;}
    cls
    
    $SPWeb = Get-SPWeb $SiteCollection
    foreach ($website in $SPWeb.webs)
        {
            foreach ($list in $website.Lists)
                {
                if ($list.CanReceiveEmail -eq $true)
                    {
                    if (($list.EmailAlias -ne $null) -and ($list.EmailAlias -eq $EmailAddressName))
                       {
                       Write-Host ""
                       Write-Host "The email belongs to list $list in $website" -ForegroundColor green
                       Write-Host "Email       : $EmailAddress@planetmail.swift.com"
                       Write-Host "Website URL :" $website.Url
                       Write-Host "List URL    :" $list.Url
                       Write-Host ""
                       Exit
    
                       }
                     }
                }
        }
    Write-Host "Not found"

    Friday, May 30, 2014 10:31 AM
  • OK, here's the latest and final version that works with subsites

    Usage : Get-EmailEnabledList.ps1 -SiteCollection https://abc... -EmailAddressName xyz

    <#
    
    .SYNOPSIS
        The script cycles through all sites and subsites inside the defined side collection and lists which library is configured with the specified email address
        
    .PARAMETER
        Get-EmailEnabledList -siteCollection <sitecollectionURL> -EmailAddress <emailAddress>
        Note that <emailAddress> is the part before the '@domain.com'
        
    .NOTES
        30 May 2014
        Thomas MALLIE
    
    #>
    
    Param(
    [string]$SiteCollection,
    [string]$EmailAddressName
    )
    
    # Load SharePoint module if not done yet
    if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {Add-PSSnapin Microsoft.SharePoint.PowerShell;}
    cls
    
    $SPSite = Get-SPSite $SiteCollection
    foreach ($website in $SPSite.AllWebs)
        {
            foreach ($list in $website.Lists)
                {
                if ($list.CanReceiveEmail -eq $true)
                    {
                    if ($list.EmailAlias -eq $EmailAddressName)
                       {
                       Write-Host ""
                       Write-Host "The email belongs to list $list in $website" -ForegroundColor green
                       Write-Host "Email       : $EmailAddress@domain.com"
                       Write-Host "Website URL :" $website.Url
                       Write-Host "List URL    :" $list.Url
                       Write-Host ""
                       Exit
    
                       }
                     }
                }
        }
    Write-Host "Not found"



    • Marked as answer by Fluidetom Friday, May 30, 2014 2:02 PM
    • Edited by Fluidetom Friday, May 30, 2014 2:04 PM
    Friday, May 30, 2014 2:00 PM