• net4.5 outlook 插件开发


    需求  做到企业邮箱和outlook自动或者手动同步,同步日历和通讯录。

    手动设置登录 

    程序运行是创建2个自定义文件夹 一个日历和一个通讯录。并且在每次保存后触发事件

       private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
    
                _iCreatePesrsonCalendar = new CreatePesrsonCalendar();
                _ICalenda = new CreatePesrsonCalendar();
                _IContacts = new ContactServeice();
                _httpInvoke = new HttpInvoke();
                CreateCustomCalendars();
                CreateContacts();
                #region 自动登录
                LoginInfo loginInfo = LoginInfo.CreateInstance();
                loginInfo.AccountID = Settings.Default.UserID.Trim();
                loginInfo.AccountPassWord = Settings.Default.Pwd; // _httpInvoke.MD5( this.txt_pwd.Text.Trim());
                loginInfo.AccountLoginTime = Common.GetTimeStamp();
                loginInfo.ASecretkey = _httpInvoke.CreateASecretkey(loginInfo);
                string b = _httpInvoke.Login(loginInfo);
                _httpInvoke.Writelog($"{loginInfo.AccountID}结果:b{b}");
                #endregion
                inspectors = this.Application.Inspectors;
                inspectors.NewInspector +=
                new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
                #region 日历触发条件
                {
                    Outlook.MAPIFolder primaryCalendar = (Outlook.MAPIFolder)this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                    foreach (Outlook.Folder personalCalendar in primaryCalendar.Folders)
                    {
                        var name = personalCalendar.Name.ToString();
                        if (name == ConstKey.foderKey)
                        {
                            personalCalendar_items = personalCalendar.Items;
                            personalCalendar_items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ItemsEvents_ItemAddCalendar);
                        }
                    }
                }
                #endregion
                #region 通讯录触发条件
                {
                    Outlook.MAPIFolder primaryContacts = (Outlook.MAPIFolder)this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                    foreach (Outlook.Folder personalContacts in primaryContacts.Folders)
                    {
                        var name = personalContacts.Name.ToString();
                        if (name == ConstKey.foderContactsKey)
                        {
                            personalContactsr_items = personalContacts.Items;
                            personalContactsr_items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ItemsEvents_ItemAddContacts);
                        }
                        
                    }
                }
                #endregion
    
                #region 初始化系统自带的日历能触发
                {
                    //_MyAppointmentsFolder = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                    //_Appointments = _MyAppointmentsFolder.Items;
                    //_Appointments.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ItemsEvents_ItemAdd);
    
                }
                #endregion
    
    
            }

      回调方法如下

          /// 日历回调
          /// </summary>
          /// <param name="Item"></param>
        public    void ItemsEvents_ItemAddCalendar(object Item)
            {
                //InboxFolderItemAdded invoked by thread
    
                LoginInfo loginInfo = LoginInfo.CreateInstance();
                if (loginInfo.Aresult)
                {
                    Console.WriteLine("自动同步*************之前先检查自己的日历数据********************日历");
    
                    #region  setp1 先检查outlook 本地的日历数据
                    var outlooklists = _iCreatePesrsonCalendar.GetCalendalFolder(ConstKey.foderKey);
                    #endregion
    
                    outlooklists.Except(outlooklists);///交叉并补
    
                    #region  setp 2 webapi 的数据
    
    
                    #endregion
    
    
                    #region setp3 开始同步
    
                    PersonalCalendarInfro p = new PersonalCalendarInfro()
                    {
                        start = DateTime.Now.AddMinutes(2),
                        end = DateTime.Now.AddMinutes(2.25),
                        description = "测试数据描述1111",
                        title = "标题1111",
                        location = "上海黄埔111111"
                    };
                    _iCreatePesrsonCalendar.SaveFolder(ConstKey.foderKey, p);
                    #endregion
    
    
                }
    
    
    
            }
           /// <summary>
           /// 通讯录回调
           /// </summary>
           /// <param name="Item"></param>
            public void ItemsEvents_ItemAddContacts(object Item)
            {
                //InboxFolderItemAdded invoked by thread
                LoginInfo loginInfo = LoginInfo.CreateInstance();
                if (loginInfo.Aresult)
                {
    
                    Console.WriteLine("自动同步*************之前先检查自己的通讯录数据********************通讯录");
    
                    Console.WriteLine("2222");
                }
            }
  • 相关阅读:
    【原创】大叔问题定位分享(21)spark执行insert overwrite非常慢,比hive还要慢
    【原创】大叔经验分享(14)spark on yarn提交任务到集群后spark-submit进程一直等待
    【原创】大叔问题定位分享(20)hdfs文件create写入正常,append写入报错
    【原创】大叔问题定位分享(19)spark task在executors上分布不均
    【原创】大数据基础之Spark(4)RDD原理及代码解析
    【原创】大叔问题定位分享(18)beeline连接spark thrift有时会卡住
    【原创】大叔问题定位分享(17)spark查orc格式数据偶尔报错NullPointerException
    【原创】大叔经验分享(13)spark运行报错WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
    linux定时任务
    source导入错码解决办法
  • 原文地址:https://www.cnblogs.com/jasontarry/p/15953701.html
Copyright © 2020-2023  润新知