EWS Managed API 2.0 设置获取邮件自动回复功能

摘要

最近要在邮件提醒功能中添加,自动回复的功能。在移动端获取用户在outlook上是否开启了自动回复功能,如果用户在outlook上开启了自动回复功能, 获取用户自动回复的内容,如果没有开启,用户可以在移动端开启自动回复并且可以设置自动回复的内容,当然,用户也可以在移动端进行关闭。

一个例子

获取用户自动回复的信息。

复制代码
    class Program
    {
        static ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
        static void Main(string[] args)
        {
            service.Url = new Uri("https://xxxxx/exchange.asmx");
            service.Credentials = new NetworkCredential("username", "userpwd", "domain");
            var oofSettiing = service.GetUserOofSettings("username@xxxx.com");           
            if (oofSettiing != null)
            {
                Console.WriteLine(oofSettiing.Duration.StartTime.ToString());
                Console.WriteLine(oofSettiing.Duration.EndTime.ToString());
                Console.WriteLine(oofSettiing.State.ToString());
                Console.WriteLine(oofSettiing.ExternalReply.Message.ToString());
                string msg = oofSettiing.ExternalReply.Message.ToString();
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(msg);
                HtmlNodeCollection pLists = doc.DocumentNode.SelectNodes(".//p");
                if (pLists != null && pLists.Count > 0)
                {
                    foreach (var item in pLists)
                    {
                        Console.WriteLine(item.InnerText);
                    }
                }
            }
            Console.Read();
        }
    }
复制代码

注意获取的自动回复内容为html标签的,所以需要过滤,这里使用HtmlAgilityPack组件,对html进行解析。

如图所示

设置自动回复

复制代码
  var myOOF = new OofSettings();
            // Set the OOF status to be a scheduled time period.
            myOOF.State = OofState.Scheduled;

            // Select the time period during which to send OOF messages.
            myOOF.Duration = new TimeWindow(DateTime.Now.AddDays(4), DateTime.Now.AddDays(5));

            // Select the external audience that will receive OOF messages.
            myOOF.ExternalAudience = OofExternalAudience.All;

            // Set the OOF message for your internal audience.
            myOOF.InternalReply = new OofReply("I'm out of office. I'll be back tomorrow. Thanks!");

            // Set the OOF message for your external audience.
            myOOF.ExternalReply = new OofReply("I'm out of the office but will reply to emails when I return. Thanks!");
            service.SetUserOofSettings("user@xxxx.com", myOOF);
复制代码

资料

https://msdn.microsoft.com/en-us/library/hh532556(EXCHG.80).aspx

posted @   wolfy  阅读(731)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
历史上的今天:
2016-03-31 js操作cookie
2014-03-31 [Head First设计模式]生活中学设计模式——组合模式
点击右上角即可分享
微信分享提示