开始的时候觉得这个是一个很小的问题,肯定有API直接可以拿到的,不过看了一圈下来,给出的最多的建议是从MAPI得到Mailbox,然后遍历目录累加大小得到Mailbox的大小。可以参考微软的KB:
http://support.microsoft.com/kb/320071
http://support.microsoft.com/kb/200160/

不过感觉都很麻烦。Exchange 2007提供了Exchange Management Shell ,里面有个脚本命令Get-MailboxStatistics可以得到Mailbox的信息,其中就包括Mailbox的大小,然后可以用c#调用这个脚本:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
            PSSnapInException snapInException = null;
            PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);
            Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);
            myRunSpace.Open();
            Pipeline pipeLine = myRunSpace.CreatePipeline();
            Command myCommand = new Command("Get-MailboxStatistics");
            pipeLine.Commands.Add(myCommand);
            CommandParameter databaseParam = new CommandParameter("database", "Main Database");
            myCommand.Parameters.Add(databaseParam);
            Collection<PSObject> commandResults = pipeLine.Invoke();
            foreach (PSObject cmdlet in commandResults)
            {
                Console.WriteLine(cmdlet.Properties["DisplayName"].Value + "\t" + cmdlet.Properties["TotalItemSize"].Value);
            }
        }
    }
}

唯一的问题是这个需要在exchange server上执行,而且也不排除这个脚本也是通过遍历目录得到的大小(执行的速度似乎也不快)。

(Visited 42 times, 1 visits today)