开发者

Sharepoint: How do i find a mail enabled list, if i only have the email?

开发者 https://www.devze.com 2023-02-10 05:04 出处:网络
I know the email from a mail开发者_开发技巧 enabled list, with I have no idea where the list lies.

I know the email from a mail开发者_开发技巧 enabled list, with I have no idea where the list lies. How do i find the list to which the email belongs to?


The code below works if you know the site collection of the list. If you don't know that, you can easily modify the code to loop a complete web application (or even a complete farm):

using System;
using Microsoft.SharePoint;

namespace FindListByEmail
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteUrl = "[complete this]";
            string email = "[complete this]"; // only the part before the @

            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();
                        }
                    }
                }
            }
        }
    }
}


To find All Incoming E-Mail Enabled Lists and Libraries in SharePoint, You can use PowerShell , C# code or SQL Server Query!

Find the PowerShell Script, SQL Query and C# code here: http://www.sharepointdiary.com/2011/06/find-all-incoming-email-enabled-lists.html#ixzz2aKvhRTDN

0

精彩评论

暂无评论...
验证码 换一张
取 消