简体   繁体   English

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

[英]How to connect to Office 365 mailbox using redemption

I want to connect to office 365 using redemption and download all the emails from the inbox and from other folders, my development machine is 我想使用赎回连接到Office 365,并从收件箱和其他文件夹下载所有电子邮件,我的开发机器是

  • Windows 10 X64 Windows 10 X64
  • Visual Studio 2015 Pro Visual Studio 2015专业版
  • Outlook is not installed on my development machine 我的开发机器上未安装Outlook
  • Installed Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1 from this link 通过此链接安装了Microsoft Exchange Server MAPI客户端和协作数据对象1.2.1
  • Used this command to register redemption.dll in my form1.cs file regsvr32.exe <fullpath>\\redemption.dll 使用此命令在我的form1.cs文件regsvr32.exe <fullpath>\\redemption.dll
  • Refrenced Interop.Redemption.dll in my project 在我的项目中刷新了Interop.Redemption.dll

This is the code I am trying to connect to Office365 mailbox 这是我尝试连接到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;    
                }
            }

This is the error I am receiving 这是我收到的错误

System.Runtime.InteropServices.COMException was unhandled 未处理System.Runtime.InteropServices.COMException
ErrorCode=-2147023541 HResult=-2147023541 Message=The specified domain either does not exist or could not be contacted ErrorCode = -2147023541 HResult = -2147023541消息=指定的域不存在或无法联系
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.ExecutionC Source = Redemption.RDOSession StackTrace:位于Redemption.IRDOSession.LogonHostedExchangeMailbox(字符串SMTPAddress,字符串用户名,字符串密码)在D:\\ Data \\ Projects \\ DotNet \\ Office365Backup \\ Source \\ Office365Backup \\ Form1.cs中的Office365Backup.Form1.CreateSession()处:D:\\ Data \\ Projects \\ DotNet \\ Office365Backup \\ Source \\ Office365Backup \\ Form1.cs中Office365Backup.Form1..ctor()的第40行:D:\\ Data \\ Projects \\中Office365Backup.Program.Main()的第19行DotNet \\ Office365Backup \\ Source \\ Office365Backup \\ Program.cs:System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)位于System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)在Microsoft。 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)处的VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在System.Threading.ExecutionContext.RunInternal(ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔状态在System.Threading.ExecutionC处) ontext.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: System.Threading.ExecutionContext.Run(System.Threading.ThreadHelper.ThreadStart()上的ontext.Run(ExecutionContextexecutionContext,ContextCallback回调,对象状态,布尔值saveSyncCtx)InnerException:

Any advice to successfully acomplish this task. 成功完成此任务的任何建议。

Thanks 谢谢

To connect to an Office 365 mailbox (or any mailbox on Exchange 2013 or 2016), you will need the Outlook version of MAPI (Outlook 2010 SP2, Outlook 2013 SP1, or Outlook 2016) - the standalone version of MAPI cannot connect as Exchange will refuse the connection. 若要连接到Office 365邮箱(或Exchange 2013或2016上的任何邮箱),您将需要Outlook版本的MAPI(Outlook 2010 SP2,Outlook 2013 SP1或Outlook 2016)-MAPI的独立版本无法连接,因为Exchange拒绝连接。

Also note that the first argument in LogonHostedExchangeMailbox is the SMTP address of the user, not a server name. 还请注意, LogonHostedExchangeMailbox中的第一个参数是用户的SMTP地址,而不是服务器名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何限制 Office 365 应用程序的邮箱访问 - How to restrict mailbox access for office 365 app 无法使用兑换访问其他用户Office 365收件箱 - Unable to access other users Office 365 inbox using redemption 创建属性get-mailbox cmdlet时使用Office365 a / c连接到联机交换时出错 - Error connect to exchange online using of Office365 a/c whencreated property get-mailbox cmdlet 连接到 Office 365 邮箱 - Connecting to office 365 mailbox 使用 Microsoft Graph 从 Office 365 邮箱中提取退回的电子邮件 - Fetch Bounced emails from Office 365 mailbox using Microsoft Graph Office 365 Exchange邮箱属性 - Office 365 Exchange Mailbox Properties 使用 Exchange web 服务读取 Office 365 邮箱 - Read an office 365 mailbox using Exchange web services 使用SMTP通过C#从Office 365邮箱发送电子邮件 - Sending email from office 365 mailbox through C# using SMTP 尝试使用 ExchangeService 从 Office 365 邮箱获取文件夹项目时出现 403 错误 - Getting 403 error when trying to get Folder items from Office 365 mailbox using ExchangeService 如何使用不使用SharePoint的外部Rest Web服务连接Office 365-SharePoint版本站点? - How to connect Office 365 - SharePoint edition site using a external Rest web service made without using SharePoint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM