问题描述
您好b $ b
我正在创建一项连接到Exchange服务并从那里获取新邮件的服务。当我手动执行代码时,我可以从那里获得新邮件。我需要收到邮件到收件箱。为了达到这个要求,我想使用EWS API的推送通知。
我已为此编写代码,但我没有收到任何新邮件和通知事件。这是一段代码:
我从以下链接获得了帮助:
[]
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;
// 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("[email protected]");
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.
推荐答案
这篇关于Exchange Server的推/拉通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!