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[
^]
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors)
{
return true;
};
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.