2014-02-20 77 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