3
votes

I plan on creating a windows service that will monitor an exchange mailbox for mails with particular subject. The attachments from such emails need to be stored in a specific folder on the network share. I believe I can achieve this using Exchange Web Services Managed API (using Exchange 2007 SP1).

If you have experience with this, please share some samples or links other than the MSDN link below that can give me a jump start.

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

2
any suggestions, please?Pratik Kothari
@Pratick Kothari Have you tried asking this question on serverfault? I think you'll have more luck on that site.calumbrodie
Are you trying to save the attachments to a folder? Or are you trying to move the emails?Sevki
I want to save the attachment to a folder by subject of the email.Pratik Kothari
You can provide more detail for a more comprehensive example.Sevki

2 Answers

9
votes

Lets say these mails are coming into your Inbox on X mailbox. You create a subscription to that folder like so

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

Now you have to set a timer and check the pull notifs

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

I hope this helps...

UPDATE Due to email request

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

Consider creating a search folder to screen the messages. You will only need to look for, and process, messages in the search folder.