使用Exchange托管API(EWS)监视邮箱附件

Pra*_*ari 3 exchange-server ews-managed-api

我计划创建一个Windows服务,它将监视具有特定主题的邮件的交换邮箱.此类电子邮件的附件需要存储在网络共享的特定文件夹中.我相信我可以使用Exchange Web服务托管API(使用Exchange 2007 SP1)实现此目的.

如果您有这方面的经验,请分享下面的MSDN链接以外的一些示例或链接,这可以给我一个快速启动.

http://msdn.microsoft.com/en-us/library/dd633696%28v=EXCHG.80%29.aspx

Sev*_*vki 9

让我们说这些邮件正在进入X邮箱的收件箱.您可以像这样创建对该文件夹的订阅

PullSubscription subscription = 
SomeExchangeService.SubscribeToPullNotifications(
new FolderId[]{ WellKnownFolderName.Inbox },1440,"",EventType.Created);
Subscriptions.Add(subscription);
Run Code Online (Sandbox Code Playgroud)

现在你必须设置一个计时器并检查拉动通知

static void Exchanger_Elapsed(object sender, ElapsedEventArgs e)
    {    
        foreach (var pullSubscription in Subscriptions)
        {
            foreach (var itemEvent in pullSubscription.GetEvents().ItemEvents)
            {
                Item item = Item.Bind(SomeExchangeService, itemEvent.ItemId);
                if (item.Subject == someString)
                {
                  //  item.Attachments do something
                  //  As in read it as a stream and write it 
                  //  to a file according to mime type and file extension
                }
            }
        }
   }
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助...

更新由于电子邮件请求

public static List<PullSubscriptionpublic static List<PullSubscription> Subscriptions = new List<PullSubscription>();> Subscriptions = new List<PullSubscription>();
Run Code Online (Sandbox Code Playgroud)