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

时间:2011-04-13 19:07:49

标签: exchange-server ews-managed-api

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

如果您有使用此操作的经验,请分享下面的MSDN链接以外的一些示例或链接,这可以让我快速启动。

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

2 个答案:

答案 0 :(得分:9)

让我们说这些邮件正在进入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
                }
            }
        }
   }

我希望这会有所帮助......

更新由于电子邮件请求

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

答案 1 :(得分:0)

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