احصل على رسالة البريد الوارد من خادم Exchange باستخدام صافي

StackOverflow https://stackoverflow.com/questions/447413

  •  22-07-2019
  •  | 
  •  

سؤال

وأي شخص يعرف كيفية القيام بذلك؟

ولست بحاجة لخلق الخدمة التي سوف الاتصال بالخادم الصرف وتحميل الرسائل من أي وقت مضى س دقيقة ...

وذلك بفضل!

هل كانت مفيدة؟

المحلول

وأنت ربما تريد استخدام WEBDAV. وهنا جيدة المقالة حول هذا الموضوع

وأيضا، وهنا الإشارة MSDN على مخزن Exchange

نصائح أخرى

وأي إصدار من Exchange Server الذي تستخدمه؟ اذا كان عام 2007، يمكنك استخدام API خدمة ويب . إن أسلوب FindItem تمكنك من الوصول إلى العناصر الموجودة في مجلد معين.

وأو مرة أخرى إذا لعام 2007 يمكنك استخدام بوويرشيل، استضافت في التطبيق صافي

يرجى زيارة <لأ href = "http://www.aspose.com/documentation/.net-components/aspose.network-for-.net/managing-emails-on-exchange-server.html" يختلط = "noreferrer نوفولو"> http://www.aspose.com/documentation/.net-components/aspose.network-for-.net/managing-emails-on-exchange-server.html ، إذا كنت ترغب في استخدام مكتبات 3rd الطرف. Aspose.Network يدعم الوصول إلى رسائل البريد الإلكتروني من Exchange Server علبة، وحفظ لملف في يمل أو جي اس الشكل.

ولقد فعلت ذلك باستخدام ملقم Exchange 2010 وخدمة Windows في C #. I استرداد الرسائل من البريد الوارد، والوصول إلى بيانات البريد وتحرير موضوع البريد الإلكتروني (حاليا الثابت ترميز) ونقله إلى مجلد آخر، محفوظ، من علبة الوارد. I عرض النتائج في التطبيق وحدة التحكم لأغراض الاختبار حتى أنا بحاجة إلى نشر هذه. لجعلها تحقق كل س دقيقة، إضافة مهمة إكس / وظيفة لمهام ويندوز المجدولة. هنا هو رمز:

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);                            
                    }
                }
        }
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top