2014-02-20 76 views
1

我一直在做一堆关于如何从EWS交换中获得邮件跟踪报告的研究,而且似乎找不到任何东西。我打算构建一个刮擦日志文件的应用程序,但是如果我可以通过EWS来完成,那么对于我所做的更好。有任何想法吗?EWS邮件跟踪报告

+0

您还在寻找解决方案吗?您的邮件跟踪报告需要什么信息? –

+0

@MimiGentz是的,我仍然在寻找解决方案。我需要能够通过收件人列表获取每个用户发送的所有电子邮件,以确定发送的电子邮件是内部还是外部。 – cal5barton

回答

2

我终于能够为我的问题创建一个解决方案。我在C#中使用Powershell来发送命令来交换和解析消息跟踪日志。为此,您需要确保您用于连接交换的用户有权使用MessageTrackingLog作为交换。我使用的用户可以访问记录管理角色。这里是允许我连接并获取消息跟踪日志的代码。

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Net; 
using System.Security.Cryptography.X509Certificates; 
using System.Text; 
using System.Management.Automation; 
using System.Collections.ObjectModel; 
using System.Management.Automation.Runspaces; 
using System.Security; 
using System.Management.Automation.Remoting; 


namespace ExchangeConnection 
{ 
class ExchangeShell 
{ 

    //Credentials 
    const string userName = "username"; 
    const string password = "password"; 

    private PowerShell InitializePS() 
    { 

     PSCredential credential = new PSCredential(userName, SecurePassword()); 
     WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("exchange server url/Powershell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); 
     connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos; 
     connectionInfo.MaximumConnectionRedirectionCount = 5; 
     connectionInfo.SkipCNCheck = true; 
     connectionInfo.OpenTimeout = 999999; 

     Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo); 
     runspace.Open(); 
     PowerShell powershell = PowerShell.Create(); 
     powershell.Runspace = runspace; 
     return powershell; 

    } 

    private SecureString SecurePassword() 
    { 
     System.Security.SecureString securePassword = new System.Security.SecureString(); 
     foreach (char c in password) 
     { 
      securePassword.AppendChar(c); 
     } 
     return securePassword; 
    } 

    public void GetMessageTrackingLog(string sender) 
    { 
     PowerShell ps = InitializePS(); 

     ps.AddCommand("Get-MessageTrackingLog"); 
     ps.AddParameter("Start", DateTime.Now.AddHours(-24).ToString()); 
     ps.AddParameter("ResultSize", "Unlimited"); 
     ps.AddParameter("Sender", sender); 
     ps.AddParameter("EventId", "SEND"); 
     Collection<PSObject> results = ps.Invoke(); 
     Console.WriteLine("|----Sender----|----Recipients----|----DateTime----|----Subject----|"); 
     foreach (var r in results) 
     { 
      string senders = r.Properties["Sender"].Value.ToString(); 
      string recipients = r.Properties["Recipients"].Value.ToString(); 
      string timestamp = r.Properties["Timestamp"].Value.ToString(); 
      string subject = r.Properties["MessageSubject"].Value.ToString(); 
      string eventID = r.Properties["EventID"].Value.ToString(); 
      string messageInfo = r.Properties["MessageInfo"].Value.ToString(); 
      Console.WriteLine("{0}|{1}|{2}|{3}", sender, recipients, timestamp, subject); 
     } 
     ps.Dispose(); 
     ps.Runspace.Dispose(); 

    } 
} 
} 
0

我认为Office 365报告Web服务将是比EWS更好的解决方案,因为它提供了大量适合您需求的邮件流量报告。这里有更多信息:Office 365 Reporting web service以及所有Exchange特定报告在此处列出:Exchange reports available in Office 365 Reporting web service。 MailTraffic *报告进出组织的消息的所有报告,因此您不必亲自编写该逻辑。

+0

你可以在内部交换服务器上使用它吗? – cal5barton

+0

不,只是Exchange Online/Office 365. –

+0

这就是我遇到的问题。我有一个预置Exchange 2010服务器。 – cal5barton