我想使用兑换连接到Office 365并从收件箱和其他文件夹下载所有电子邮件,我的开发机器
regsvr32.exe <fullpath>\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 =指定的 域名要么不存在要么无法联系
Source = Redemption.RDOSession StackTrace: at Redemption.IRDOSession.LogonHostedExchangeMailbox(String SMTPAddress,String UserName,String Password) 在Office 365Backup.Form1.CreateSession()在D:\ Data \ Projects \ DotNet \ Office365Backup \ Source \ Office365Backup \ Form1.cs:line 40 在Office 365Backup.Form1..ctor()中的D:\ Data \ Projects \ DotNet \ Office365Backup \ Source \ Office365Backup \ Form1.cs:line 19 在Office365Backup.Program.Main()中的D:\ Data \ Projects \ DotNet \ Office365Backup \ Source \ Office365Backup \ Program.cs:line 25 在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args) 在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx) 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) 在System.Threading.ThreadHelper.ThreadStart()InnerException:
成功完成此任务的任何建议。
由于
答案 0 :(得分:1)
要连接到Office 365邮箱(或Exchange 2013或2016上的任何邮箱),您将需要Outlook版本的MAPI(Outlook 2010 SP2,Outlook 2013 SP1或Outlook 2016) - 独立版本的MAPI无法连接因为Exchange会拒绝连接。
另请注意,LogonHostedExchangeMailbox
中的第一个参数是用户的SMTP地址,而不是服务器名称。