【问题标题】:How to connect to Office 365 mailbox using redemption如何使用兑换连接到 Office 365 邮箱
【发布时间】:2018-03-14 16:47:30
【问题描述】:

我想使用兑换连接到 Office 365 并从收件箱和其他文件夹中下载所有电子邮件,我的开发机器是

  • Windows 10 X64
  • Visual Studio 2015 专业版
  • 我的开发机器上没有安装 Outlook
  • link 安装 Microsoft Exchange Server MAPI 客户端和协作数据对象 1.2.1
  • 使用此命令在我的 form1.cs 文件中注册 redemption.dll regsvr32.exe <fullpath>\redemption.dll
  • 在我的项目中引用了 Interop.Redemption.dll

这是我尝试连接到 Office365 邮箱的代码

  string codeBase = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            path = Path.GetDirectoryName(path);

            RedemptionLoader.DllLocation32Bit = string.Concat(path, @"\Redemption.dll");
            RedemptionLoader.DllLocation64Bit = string.Concat(path, @"\Redemption64.dll");

            RDOSession session = RedemptionLoader.new_RDOSession();

            session.LogonHostedExchangeMailbox("smtp.office365.com", "abc@domain.com","xxxx");// getting error at this line               

            if (session.LoggedOn)
            {
                RDOFolder contactsFolder;    
                contactsFolder = session.GetDefaultFolder(rdoDefaultFolders.olFolderContacts);
                var i = contactsFolder.Folders.Count;

                foreach (var item in contactsFolder.Folders)
                {
                    var obj = (RDOFolder2)item;
                    var name = obj.AddressBookName;    
                }
            }

这是我收到的错误

System.Runtime.InteropServices.COMException 未处理
ErrorCode=-2147023541 HResult=-2147023541 Message=指定的 域不存在或无法联系
来源 = Redemption.RDOSession StackTrace: 在 Redemption.IRDOSession.LogonHostedExchangeMailbox(字符串 SMTP 地址、字符串用户名、字符串密码) 在 D:\Data\Projects\DotNet\Office365Backup\Source\Office365Backup\Form1.cs:line 中的 Office365Backup.Form1.CreateSession() 40 在 D:\Data\Projects\DotNet\Office365Backup\Source\Office365Backup\Form1.cs:line 中的 Office365Backup.Form1..ctor() 19 在 D:\Data\Projects\DotNet\Office365Backup\Source\Office365Backup\Program.cs:line 中的 Office365Backup.Program.Main() 25 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext、ContextCallback 回调、对象状态、布尔值 保留SyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback 回调, 对象状态, Boolean 保留SyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart() InnerException:

成功完成此任务的任何建议。

谢谢

【问题讨论】:

    标签: c# .net multithreading visual-studio outlook-redemption


    【解决方案1】:

    要连接到 Office 365 邮箱(或 Exchange 2013 或 2016 上的任何邮箱),您将需要 Outlook 版本的 MAPI(Outlook 2010 SP2、Outlook 2013 SP1 或 Outlook 2016) - 独立版本的 MAPI 无法连接因为 Exchange 将拒绝连接。

    还要注意LogonHostedExchangeMailbox 中的第一个参数是用户的 SMTP 地址,而不是服务器名称。

    【讨论】:

    • 你是说他用的是单机版,需要用Outlook版的MAPI?您是否从他的声明中得知 Outlook 未安装在他的开发机器上?编辑:另外,MAPI 客户端是否意味着独立?
    • @Dmitry,您所说的 Outlook 版本的 MAPI 是什么意思,您的意思是我需要安装 Outlook 2013 或 2016,或者我需要安装其他任何东西,抱歉无法获得您正在尝试的内容建议。
    • 是的,我需要安装 Outlook。这将安装 MAPI 系统。
    • @Maderas - 是的。该链接还指向旧版本的 MAPI。最新的是 2014 年的:microsoft.com/en-us/download/details.aspx?id=42040
    猜你喜欢
    • 2018-06-09
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多