Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am creating a service which connect to Exchange service and get new mail from there. I am able to get new mail from there when I execute the code manually. I need to get mail as it come to inbox. To achieve this requirement I want to use Push notification of EWS API.
I have written code for this, but I do not get any event for new mail and notification. Here is the piece of code:

I got help from the following link:
EWS Mail Notifier[^]
C#
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(
                   Object obj,
                   X509Certificate certificate,
                   X509Chain chain,
                   SslPolicyErrors errors)
                {
                    return true;
                    // TODO: check for a valid certificate
                };
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
                service.Credentials = new NetworkCredential("xxxx", "xxxx", "abc.com");
                service.Url = new Uri("https://mail.abc.com/owa/Exchange.asmx");
                service.AutodiscoverUrl("xxxx@abc.com");
               
                ServicePointManager.ServerCertificateValidationCallback = new    System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; });
                AuthenticateSecureOWA("mail.abc.com", "abc.com", "xxxx", "xxxx");
                ItemView IView = new ItemView(10);
               
                FindItemsResults<Item> findResults;
                findResults = service.FindItems(WellKnownFolderName.Inbox, IView);

                PushSubscription ps = service.SubscribeToPushNotifications(
                new FolderId[] { WellKnownFolderName.Inbox },
                new Uri("http://192.168.1.1:5050"),
                5 , null ,  EventType.NewMail);
                SubscriptionId = ps.Id;
                _listener = new TcpListener(5050);
                _listener.Start();
                _th = new Thread(new ThreadStart(ProcessIncomingMessages));
                _th.Start();

}


 private void ProcessIncomingMessages()
        {
            try
            {
                for (; ; )
                {
                    CSHTTPRequest csHttpRequest = new CSHTTPRequest(_listener.AcceptTcpClient(), this);

                    csHttpRequest.Process();
                   
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

There are some other supporting files I am using to process.

Any suggestion will be appreciated
Thanks in advance.
Posted
Updated 13-Jun-11 23:25pm
v2
Comments
Sandeep Mewara 14-Jun-11 5:25am    
Use PRE tags to format code part. It makes the question readable.

EWS urls have the following form:

"https://x.b.com/EWS/Exchange.asmx".

The link here talks about the format of the exchange service url:

http://msdn.microsoft.com/en-us/library/dd633692%28v=exchg.80%29.aspx[^]

You've used

"https://mail.abc.com/owa/Exchange.asmx"


Hope it helps.
 
Share this answer
 
Did you solved this problem?

I am also facing this.

Please help me, if you got it
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900