Shax
Shax

Reputation: 4307

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

This is the code I am trying to connect to Office365 mailbox

  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", "[email protected]","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
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:

Any advice to successfully acomplish this task.

Thanks

Upvotes: 0

Views: 3085

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

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.

Also note that the first argument in LogonHostedExchangeMailbox is the SMTP address of the user, not a server name.

Upvotes: 2

Related Questions