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



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

如果你有这方面的经验,请分享一些示例或链接,而不是下面的MSDN链接,可以给我一个跳跃的开始。

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

假设这些邮件正在进入X邮箱的收件箱。为该文件夹创建一个订阅,如下所示

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

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

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
                }
            }
        }
   }

我希望这对你有帮助。

UPDATE Due to email request

public static List<PullSubscriptionpublic static List<PullSubscription> Subscriptions = new List<PullSubscription>();> Subscriptions = new List<PullSubscription>();

考虑创建一个搜索文件夹来筛选消息。您只需要在搜索文件夹中查找和处理消息。

最新更新