2009-01-15 6 views

Répondre

2

Quelle version de Exchange Server vous utilisez? Si c'est en 2007, vous pouvez utiliser le web service API. La méthode FindItem vous permet d'accéder aux éléments d'un dossier spécifique.

+0

Le lien que vous donnez n'existe pas. Je n'arrive pas à le trouver ailleurs. pourrait-il être interrompu? –

+0

Je viens de re-testé les deux liens, et ils travaillent tous les deux pour moi. – Geoff

+0

vous avez raison ... mon mauvais. Peut-être que c'est juste moi, mais je ne peux pas trouver la DLL ou les bibliothèques que je devrais utiliser pour cela. Je cherchais depuis un moment. –

0

Ou encore si son 2007, vous pouvez utiliser powershell, hébergé dans une application .net

0

Je l'ai fait en utilisant Exchange Server 2010 et le service Windows en C#. Je récupère les e-mails de la boîte de réception, j'accède aux données de courrier, édite l'objet de l'e-mail (actuellement codé en dur) et le déplace vers un autre dossier, Saved, de la boîte de réception. J'affiche les résultats dans une application de console à des fins de test jusqu'à ce que j'ai besoin de déployer cela. Pour le vérifier toutes les x minutes, ajoutez une tâche exe/un travail aux tâches planifiées de Windows. Voici le code:

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);        
        } 
       } 
     } 
    } 
Questions connexes