首页 > 其他分享 >Microsoft.Exchange.WebServices.Data;

Microsoft.Exchange.WebServices.Data;

时间:2023-05-15 14:33:55浏览次数:44  
标签:Console ewsClient endDate WebServices WriteLine new Data Microsoft

using Microsoft.Exchange.WebServices.Data;

using Microsoft.Identity.Client;

using System;

using System.Configuration;

 

namespace EwsOAuth

{

    class Program

    {

        static async System.Threading.Tasks.Task Main(string[] args)

        {

            // Using Microsoft.Identity.Client 4.22.0

            var cca = ConfidentialClientApplicationBuilder

                .Create(ConfigurationManager.AppSettings["appId"])

                .WithClientSecret(ConfigurationManager.AppSettings["clientSecret"])

                .WithTenantId(ConfigurationManager.AppSettings["tenantId"])

                // Use the next line of code only in a 21V environment

                .WithAuthority(AzureCloudInstance.AzureChina, ConfigurationManager.AppSettings["tenantId"])

                .Build();

            //the permission scope required for EWS access

            var ewsScopes = new string[] { "https://partner.outlook.cn/.default" };

 

            try

            {

                //make the token request

                var authResult = await cca.AcquireTokenForClient(ewsScopes).ExecuteAsync();

 

                // Configure the ExchangeService with the access token

                var ewsClient = new ExchangeService();

                ewsClient.Url = new Uri("https://partner.outlook.cn/EWS/Exchange.asmx");

                ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);

                ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");

 

                //Include x-anchormailbox header

                ewsClient.HttpHeaders.Add("X-AnchorMailbox", "[email protected]");

 

                // Make an EWS call

                               

                DateTime endDate = DateTime.Now;

                DateTime startDate = endDate.AddDays(-30);

                CalendarFolder calendar = CalendarFolder.Bind(ewsClient, WellKnownFolderName.Calendar, new PropertySet());

                CalendarView cView = new CalendarView(startDate, endDate);

                cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

                FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

                Console.WriteLine("\nThe first " + " appointments on your calendar from " + startDate.Date.ToShortDateString() +

             " to " + endDate.Date.ToShortDateString() + " are: \n");

                foreach (Appointment a in appointments)

                {

                    Console.Write("Subject: " + a.Subject.ToString() + " ");

                    Console.Write("Start: " + a.Start.ToString() + " ");

                    Console.Write("End: " + a.End.ToString());

                    Console.WriteLine();

                }

            }

            catch (MsalException ex)

            {

                Console.WriteLine($"Error acquiring access token: {ex}");

            }

            catch (Exception ex)

            {

                Console.WriteLine($"Error: {ex}");

            }

 

            if (System.Diagnostics.Debugger.IsAttached)

            {

                Console.WriteLine("Hit any key to exit...");

                Console.ReadKey();

            }

        }

    }

}

 

标签:Console,ewsClient,endDate,WebServices,WriteLine,new,Data,Microsoft
From: https://www.cnblogs.com/mqingqing123/p/17401801.html

相关文章

  • OData WebAPI实践-兼容OData集合响应
    本文属于OData系列文章引言OData是一个开放标准,已经在oasis组织标准化,因此我们可以在标准的官网查询到OData的标准请求与返回形式:ODataJSONFormatVersion4.01(oasis-open.org)针对不同的数据类型,输出返回的格式也不尽相同,涉及的内容非常多。日常使用OData的过程......
  • Microsoft Login Error 异常
    MicrosoftLoginError异常捕捉异常,记录异常欢迎关注公-众-号【TaonyDaily】、留言、评论,一起学习。文章来源:刘俊涛的博客若有帮助到您,欢迎点赞、转发、支持,您的支持是对我坚持最好的肯定(_)......
  • 火山引擎DataTester:A/B实验平台数据集成技术分享
    DataTester的数据集成系统,可大幅降低企业接入A/B实验平台门槛。 当企业想要接入一套A/B实验平台的时候,常常会遇到这样的问题:企业已经有一套埋点系统了,增加A/B实验平台的话需要重复做一遍埋点,费时费力;企业有多个客户端和数据中台并行的情况,这些不同来源的数据难以整合......
  • python的dataframe通过query使用dict字典查询
    示例```params={"坐席姓名":"唐红成"}query_string='and'.join(  [f'({key}=="{val}")'iftype(val)==strelsef'({key}=={val})'forkey,valinparams.items()])df.query(query_string)```......
  • Exadata X4-2 刷机至18.1.34版本遇到的问题
    客户有一套ExadataX4-2,计划从目前的11.2.3.3.1版本升级至18.1.34版本,但其中的一台计算节点在升级过程中遇到很多的故障,最终决定将这个已经升级失败的计算节点刷机至18.1.34版本。 本文主要记录将ExadataX4-2刷机至18.1.34版本时,遇到的一些异常情况。在刷机刚开始不久,会进入......
  • DataBaseJ
    一、插件描述DataBaseJ是一款依赖DataBaseTools插件开开发的IntellijIDEA插件。用于处理数据相关的问题。 二、插件支持目前DataBaseJ的支持如下:1、支持根据查询结果导出对于结果数据结果集。2、支持Excel2003和Excel2007数据格式的导出。3、支持SQ......
  • WPF入门教程系列二十四——DataGrid使用示例(1)
    WPF入门教程系列目录WPF入门教程系列二——Application介绍WPF入门教程系列三——Application介绍(续)WPF入门教程系列四——Dispatcher介绍WPF入门教程系列五——Window介绍WPF入门教程系列十一——依赖属性(一)WPF入门教程系列十五——WPF中的数据绑定(一)      ......
  • MySQL text类型出现报错 Data truncation: Data too long for column...
    MySQL5.7数据库字段类型为:text 代码中限制了长度为50000 结果出现异常 结论:MySQL5以上版本中varchar类型的长度限制是以字符数为单位的,比如:“你好”是2个字符text类型则是以字节数为单位的,这里我们的数据库字段编码为utf8mb4,每个中文字符占3个字节,所以“你好”是......
  • Salesforce LWC学习(四十四) Datatable 显示日期类型的有趣点思考
    本篇参考:https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_salesforce_modules背景:项目中经常用到datatable显示日期类型字段,并要求日期类型字段基于指定格式显示。这种是一个很常见的需求,而且demo很容易找到,无论是官方文档中还是......
  • Zookeeper详细教程-data01
    Zookeeper详细教程一、Zookeeper介绍1.1什么是zookeeper​ Zookeeper是一个分布式的、高性能的、开源的分布式系统的协调(Coordination)服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的一个重要的组件。它是一个为分布式应用提供一致性服务的软件。1.2zookeeper应用场......