4

有人知道该怎么做吗?

我需要创建一个服务,该服务将连接到交换服务器并每 x 分钟下载一次消息......

谢谢!

4

5 回答 5

2

您可能想要使用 WebDAV。这是一篇关于这个主题的好文章

此外,这是Exchange Store上的 MSDN 参考

于 2009-01-15T16:36:41.273 回答
2

您使用的是哪个版本的 Exchange Server?如果是 2007 年,您可以使用Web 服务 APIFindItem方法将允许您访问特定文件夹中的项目。

于 2009-01-15T16:39:43.607 回答
0

或者,如果它是 2007 年,您可以使用托管在 .net 应用程序中的 powershell

于 2009-01-28T10:46:46.787 回答
0

如果您有兴趣使用 3rd 方库,请访问http://www.aspose.com/documentation/.net-components/aspose.network-for-.net/managing-emails-on-exchange-server.html 。Aspose.Network 支持从 Exchange Server 收件箱访问电子邮件并以 eml 或 msg 格式保存到文件。

于 2009-09-19T20:40:25.230 回答
0

我在 C# 中使用 Exchange Server 2010 和 Windows 服务完成了这项工作。我从收件箱中检索邮件,访问邮件数据,编辑电子邮件的主题(当前是硬编码的)并将其从收件箱中移至另一个文件夹“已​​保存”。我在控制台应用程序中显示结果以进行测试,直到我需要部署它。要使其每 x 分钟检查一次,请将 exe 任务/作业添加到 Windows 计划任务。这是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Exchange101;
using Microsoft.Exchange.WebServices.Data;

namespace Exchange101
{      
    class Notifications
    {
      static ExchangeService service = Service.ConnectToService(UserDataFromConsole.GetUserData(), new TraceListener());

    static void Main(string[] args)
    {
        //SetStreamingNotifications(service);
        RecieveMails(service);

        Console.WriteLine("\r\n");
        Console.WriteLine("Press or select Enter...");
        Console.Read();
    }

    static void RecieveMails(ExchangeService service)
    {
        // Create a view with a page size of 100.
        ItemView view = new ItemView(10);

        // Indicate that the base property will be the item identifier
        view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
        view.PropertySet.Add(ItemSchema.IsAssociated);

        // Set the traversal to associated. (Shallow is the default option; other options are Associated and SoftDeleted.)
        view.Traversal = ItemTraversal.Associated;

        // Send the request to search the Inbox.
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, view);

        // Output a list of the item classes for the associated items
        foreach (Item item in findResults)
        {
            Console.WriteLine(item.ItemClass);
        }

        findResults = service.FindItems(
        WellKnownFolderName.Inbox,
        new ItemView(10)); //10 is the number of mails to fetch

        foreach (Item item in findResults.Items)
        {        
            //this needs to be here to recieve the message body
            MessageBody messageBody = new Microsoft.Exchange.WebServices.Data.MessageBody();
            List<Item> items = new List<Item>();
            if (findResults.Items.Count > 0) // Prevent the exception
            {
                foreach (Item item2 in findResults)
                {
                    items.Add(item2);
                }
            }
            service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);

            messageBody = item.Body.ToString();

            Console.WriteLine("==========================================================================");
            Console.WriteLine("IsNew: " + item.IsNew);
            Console.WriteLine("To: " + item.DisplayTo);
            Console.WriteLine("Subject: " + item.Subject);
            Console.WriteLine("Message Body: " + item.Body.ToString());
            Console.WriteLine("Date & Time Received: " + item.DateTimeReceived);
            Console.WriteLine("HasAttachments: " + item.HasAttachments);               

            //this is just what I have to do later
            //CreateNewWorkflowFromEmail();
            //if (WorkflowWasCreated) then move email to saved folder

            //here I change the subject and move the mail to my custom folder "Saved"
            Folder rootfolder = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
            rootfolder.Load();

            foreach (Folder folder in rootfolder.FindFolders(new FolderView(100)))
            {
                // This IF limits what folder the program will seek
                if (folder.DisplayName == "Saved")
                {
                    var fid = folder.Id;
                    //Console.WriteLine(fid);                        
                    item.Load();
                    item.Subject = ("WF1234567 - " + item.Subject);
                    item.Update(ConflictResolutionMode.AlwaysOverwrite);
                    item.Move(fid);                            
                    }
                }
        }
    }
于 2013-03-01T14:35:38.820 回答