摘要

查找一些关于流通知订阅邮件的资料,这里整理一下。

核心代码块

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Timers;
using Exchange101;
using Microsoft.Exchange.WebServices.Data; namespace Exchange101
{
// This sample is for demonstration purposes only. Before you run this sample, make sure that the code meets the coding requirements of your organization.
class Notifications
{
static ExchangeService service = Service.ConnectToService(UserDataFromConsole.GetUserData(), new TraceListener());
private static AutoResetEvent Signal; static void Main(string[] args)
{
SetStreamingNotifications(service); // Wait for the application to exit
Signal = new AutoResetEvent(false);
Signal.WaitOne(); }
static void SetStreamingNotifications(ExchangeService service)
{
// Subscribe to streaming notifications on the Inbox folder, and listen
// for "NewMail", "Created", and "Deleted" events.
StreamingSubscription streamingsubscription = service.SubscribeToStreamingNotifications(
new FolderId[] { WellKnownFolderName.Inbox },
EventType.NewMail,
EventType.Created,
EventType.Deleted); StreamingSubscriptionConnection connection = new StreamingSubscriptionConnection(service, ); connection.AddSubscription(streamingsubscription);
// Delegate event handlers.
connection.OnNotificationEvent +=
new StreamingSubscriptionConnection.NotificationEventDelegate(OnEvent);
connection.OnSubscriptionError +=
new StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnError);
connection.OnDisconnect +=
new StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnDisconnect);
connection.Open(); Console.WriteLine("--------- StreamSubscription event -------");
} static private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
{
// Cast the sender as a StreamingSubscriptionConnection object.
StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;
// Ask the user if they want to reconnect or close the subscription.
ConsoleKeyInfo cki;
Console.WriteLine("The connection to the subscription is disconnected.");
Console.WriteLine("Do you want to reconnect to the subscription? Y/N");
while (true)
{
cki = Console.ReadKey(true);
{
if (cki.Key == ConsoleKey.Y)
{
connection.Open();
Console.WriteLine("Connection open.");
Console.WriteLine("\r\n");
break;
}
else if (cki.Key == ConsoleKey.N)
{
Signal.Set();
bool isOpen = connection.IsOpen; if (isOpen == true)
{
// Close the connection
connection.Close();
}
else
{
break;
}
}
}
} } static void OnEvent(object sender, NotificationEventArgs args)
{
StreamingSubscription subscription = args.Subscription; // Loop through all item-related events.
foreach (NotificationEvent notification in args.Events)
{ switch (notification.EventType)
{
case EventType.NewMail:
Console.WriteLine("\n-------------Mail created:-------------");
break;
case EventType.Created:
Console.WriteLine("\n-------------Item or folder created:-------------");
break;
case EventType.Deleted:
Console.WriteLine("\n-------------Item or folder deleted:-------------");
break;
}
// Display the notification identifier.
if (notification is ItemEvent)
{
// The NotificationEvent for an email message is an ItemEvent.
ItemEvent itemEvent = (ItemEvent)notification;
Console.WriteLine("\nItemId: " + itemEvent.ItemId.UniqueId);
}
else
{
// The NotificationEvent for a folder is a FolderEvent.
FolderEvent folderEvent = (FolderEvent)notification;
Console.WriteLine("\nFolderId: " + folderEvent.FolderId.UniqueId);
}
}
}
static void OnError(object sender, SubscriptionErrorEventArgs args)
{
// Handle error conditions.
Exception e = args.Exception;
Console.WriteLine("\n-------------Error ---" + e.Message + "-------------");
} }
}

相关资料

https://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx

https://blogs.msdn.microsoft.com/emeamsgdev/2013/04/16/ews-streaming-notification-sample/

EWS 流通知订阅邮件的更多相关文章

  1. EWS 通过SubscribeToPullNotifications订阅Exchange新邮件提醒

    摘要 在ews中提供了一种拉通知的方式获取服务端邮件的操作,通过这种方式客户端可以订阅该通知,在邮箱有变化的时候,可以收到通知. 工作方式 EWS 通知是在订阅的基础上处理的.通常是一个订阅每个邮箱, ...

  2. [EWS]如何: 通过使用 Exchange 中的 EWS 流有关邮箱事件的通知

    摘要 在之前的文章中,介绍ews拉通知的模式订阅邮件.详情可阅读这篇文章:EWS 通过SubscribeToPullNotifications订阅Exchange新邮件提醒 ,可以看到拉通知的模式,是 ...

  3. EWS 通过SubscribeToPullNotifications订阅Exchange删除邮件

    摘要 在使用拉通知的方式监听exchange邮件的时候,无法监听到收件箱删除的邮件.最后通过调试发现,在删除收件箱邮件的时候,是将收件箱的邮件移动到了deleted item文件夹,会触发Moved事 ...

  4. Dynamic CRM 2013学习笔记(三十四)自定义审批流5 - 自动邮件通知

    审批过程中,经常要求自动发邮件:审批中要通知下一个审批人进行审批:审批完通知申请人已审批完:被拒绝后,要通知已批准的人和申请人.下面详细介绍如何实现一个自动发邮件的插件:   1. 根据审批状态来确定 ...

  5. SignalR主动通知订阅者示例

    html代码: <script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script> <scri ...

  6. EWS 邮件提醒

    摘要 之前做的邮件提醒的项目,最近需要优化,由于使用了队列,但即时性不是特别好,有队列,就会出现先后的问题,最近调研了exchange 流通知的模式,所以想使用流通知模式和原先的拉取邮件的方法结合,在 ...

  7. 订阅Linux内核的邮件列表

    1.发送订阅邮件 注意:一定不要使用像Foxmail这样的第三方邮件客户端,因为发送的邮件会转码,导致订阅不成功,推荐使用Gmail,直接登录进去发送. 发送邮件内容: 接收人:majordomo@v ...

  8. 使用TheFolderSpy监控文件夹的变化-邮件通知

    一.概述 当我们的文档或者代码文件发布在公网.共享文件夹中,其他用户具备访问或修改的权限时,就存在文档被覆盖或删除的分享.另外一个典型的场景,发布在Web服务器上的网页文件,在网站版本不更新的时间,服 ...

  9. 微软BI 之SSRS 系列 - 报表邮件订阅中 SMTP 服务器匿名访问与 Windows验证, 以及如何成功订阅报表的实例

    这篇文章源于在上一篇博文中有园友提出订阅 SSRS 报表时的一个问题,  于是就好好总结了一下,把有关 SSRS 报表订阅的要点和容易出现问题的地方写出来,希望对大家有所帮助! 参看上一篇博文 - S ...

随机推荐

  1. oracle查询语句查询增加一列内容

    select a,sys_guid() as b from mytable sys_guid() 是生成带分隔符(-)的GUID的自定义函数 查询B表的内容插入A表,MY_ID是A表的主键不可为空,因 ...

  2. Flask中的before_request和after_request

    1.@app.before_request 在请求(request)之前做出响应 @app.before_request 也是一个装饰器,他所装饰的函数,都会在请求进入视图函数之前执行 2.@app. ...

  3. spring boot 中使用LUA脚本

    编写LUA脚本 该脚本功能:先检查redis中某个key的值是否与期望的值V1一致,如果一致则将其修改为新的值V2并返回true,否则返回false.其实就是CAS. local current = ...

  4. C# 开发代码标准

    开发标准文件 文件名称:C#开发规范 版 本:V2.0 前言 目的是为了规范每个人的编程风格,为确保系统源程序可读性,从而增强系统可维护性,制定下述编程规范,以规范系统各部分编程.系统继承的其它资源中 ...

  5. spring mvc 使用kaptcha配置生成验证码实例

    SpringMVC整合kaptcha(验证码功能) 一.依赖 <dependency> <groupId>com.github.penggle</groupId> ...

  6. 06-03 Java 面向对象思想概述、开发设计特征,类和对象的定义使用,对象内存图

    面向对象思想概述.开发设计特征 1:面向对象思想 面向对象是基于面向过程的编程思想. 面向过程:强调的是每一个功能的步骤 面向对象:强调的是对象,然后由对象去调用功能 2:面向对象的思想特点 A:是一 ...

  7. [Umbraco] 熟悉管理页面

    登录到umbraco管理界面后,发现其后台管理页很简洁 首页看到左侧部分是一个Content和Sections,右侧是管理区域 介绍各个Sections代表的含义: "Content&quo ...

  8. 阿里Java开发规范&谷歌Java开发规范&华为Java开发规范&Tab键和空格比较&Eclipse的Tab键设置 总结

    现在收集到如下有用的信息: 阿里巴巴公开的Java开发规范:https://yq.aliyun.com/articles/69327?utm_content=m_10088 google公开的Java ...

  9. java和js获取当前天之后或之前7天(任意)日期

    一.获取过去第几天的日期(- 操作) 或者 未来 第几天的日期( + 操作) /** * 获取过去第几天的日期(- 操作) 或者 未来 第几天的日期( + 操作) * * @param past * ...

  10. Javascript图片预加载详解 分类: JavaScript HTML+CSS 2015-05-29 11:01 768人阅读 评论(0) 收藏

    预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ...