Click here to Skip to main content
12,350,610 members (24,636 online)
Click here to Skip to main content

Stats

42.3K views
2.3K downloads
17 bookmarked
Posted

EWS Mail Notifier

, 19 Apr 2010 CPOL
Simple mail notifier for Exchange
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EWSConsoleNotify
{
    class PushNotification
    {
        private Notify _parent;
        
        public PushNotification(Notify Parent)
        {
            _parent = Parent;
        }

        public SendNotificationResultType ProcessNotification(SendNotificationResponseType SendNotification)
        {          
            SendNotificationResultType result = new SendNotificationResultType(); // Notification's result
            bool unsubscribe = false; 

            ResponseMessageType[] responseMessages = SendNotification.ResponseMessages.Items; // Response messages

            foreach (ResponseMessageType responseMessage in responseMessages)
            {
                if (responseMessage.ResponseCode != ResponseCodeType.NoError)
                {                    
                    result.SubscriptionStatus = SubscriptionStatusType.Unsubscribe;
                    return result;
                }

                NotificationType notification = ((SendNotificationResponseMessageType)responseMessage).Notification;

                string subscriptionId = notification.SubscriptionId;
              
                // If subscription Id is not the current subscription Id, unsubscribe
                if (subscriptionId != _parent.SubscriptionId)
                {
                    unsubscribe = true;
                }
                else
                {
                    for (int c = 0; c < notification.Items.Length; c++)
                    {
                        // Get only new mail events
                        if (notification.ItemsElementName[c].ToString() == "NewMailEvent")
                        {
                            BaseObjectChangedEventType bocet = (BaseObjectChangedEventType)notification.Items[c];

                            _parent.ShowMessage(((ItemIdType)bocet.Item).Id);
                        }
                    }
                }           
            }

            if (unsubscribe)
            {
                result.SubscriptionStatus = SubscriptionStatusType.Unsubscribe;
            }
            else
            {
                result.SubscriptionStatus = SubscriptionStatusType.OK;
            }


            return result;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

avg360
Software Developer
Spain Spain
MCTS: .NET Framework 3.5 ASP.NET Applications

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 19 Apr 2010
Article Copyright 2010 by avg360
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid