如何使用兑换连接到 Office 365 邮箱

How to connect to Office 365 mailbox using redemption

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

这是我尝试连接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 was unhandled
ErrorCode=-2147023541 HResult=-2147023541 Message=The specified domain either does not exist or could not be contacted
Source=Redemption.RDOSession StackTrace: at Redemption.IRDOSession.LogonHostedExchangeMailbox(String SMTPAddress, String UserName, String Password) at Office365Backup.Form1.CreateSession() in D:\Data\Projects\DotNet\Office365Backup\Source\Office365Backup\Form1.cs:line 40 at Office365Backup.Form1..ctor() in D:\Data\Projects\DotNet\Office365Backup\Source\Office365Backup\Form1.cs:line 19 at Office365Backup.Program.Main() in D:\Data\Projects\DotNet\Office365Backup\Source\Office365Backup\Program.cs:line 25 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

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

谢谢

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

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