1

I am trying to login to a mailbox using the following code, but it logs in to my local outlook mailbox instead of the one specified in the code in oNS.Logon("account", "password", false, false) line. Do I need to use Redemption.RDOSession for the same ? If so, how to use it in C#?

oApp = new Outlook.Application();
oNS = oApp.GetNamespace("mapi");
oNS.Logon("account", "password", false, false);        

var EntryID = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).EntryID;
var StoreID = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).StoreID;

var folderID = oNS.GetFolderFromID(EntryID, StoreID);

When I use RDSession.LogonHostedExchangeMailbox, the error I am getting is as follows:

GetAutodiscoverForEmailAddress: There are no autodiscover servers in the AD for this address Error in WinHttpSendRequest(collabera.com/autodiscover/autodiscover.xml): ERROR_WINHTTP_TIMEOUT Error in WinHttpSendRequest(collaberainc.mail.onmicrosoft.com/autodiscover/autodiscover.xml): ERROR_WINHTTP_NAME_NOT_RESOLVED Error in WinHttpSendRequest(autodiscover.collaberainc.mail.onmicrosoft.com/autodiscover/autodiscover.xml): ERROR_WINHTTP_CANNOT_CONNECT HTTP error 401 from https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml Server response:

GetAutodiscoverUrlFromDns error: DNS lookup error using 172.17.18.50:DNS Server Reports Query Name Error DNS lookup error using 172.30.30.53:DNS Server Reports Query Name Error DNS lookup error using 172.30.30.11:DNS Server Reports Query Name Error Expected HTTP_STATUS_REDIRECT, received 403 Could not retrieve any autodiscover URLs from DNS lookup

Kanu Priya
  • 77
  • 1
  • 8

1 Answers1

2

Namespace.Logon in OOM takes the name of an existing profile (as shown in Control Panel | Mail | Show Profiles), not the name of a mailbox.

Since you tagged your question "Outlook-Redemption", I assume you are looking for a Redemption solution. In that case, use RDOSession.LogonHostedExchangeMailbox - it indeed takes an SMTP address of an Exchange mailbox, configures a temporary profile, logs in, and deletes the profile.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I am trying to use `Redemption.RDOSession`. I am still not able to find out how to use it. Can you tell me how to use it in C# to logon to a particular email profile ? – Kanu Priya Feb 26 '19 at 07:06
  • I figured how to add `Redemption` library to my C# code? I had to use http://www.dimastr.com/redemption/download.htm for downloading and adding the reference. Thanks for help. How to proceed further to logon to a specific profile in C# ? – Kanu Priya Feb 26 '19 at 07:36
  • RDOSession.Logon (just like Namespace.Logon) takes the name of the existing profile. If you pass an empty string, it will use the default profile. – Dmitry Streblechenko Feb 26 '19 at 13:24
  • I got busy with somwething else. That's why I am replying late. I tried RDOSession.Logon. It works fine. But now how to get sender's email using Redemption library ? – Kanu Priya Mar 01 '19 at 06:23
  • Also `RDOSession.Logon` works for local mailbox on my machine. `RDOSession.LogonHostedExchangeMailbox` gives me ERROR_WINHTTP_NAME_NOT_RESOLVED error. – Kanu Priya Mar 01 '19 at 06:49
  • By "ender's email", do you mean the address of the current user? Use RDOsession.CurrentUser for that. – Dmitry Streblechenko Mar 01 '19 at 15:37
  • How are you calling LogonHostedExchangeMailbox? – Dmitry Streblechenko Mar 01 '19 at 15:37
  • By Sender's email, I mean From of Outlook mailbox. I am using LogonHostedExchangeMailbox as in `RDSession.LogonHostedExchangeMailbox("kanu.priya@xyz.com", "kanu.priya", "password")`. – Kanu Priya Mar 04 '19 at 03:39
  • Then RDOSession.CurrentUser is what you want. But you already know the email address since you pass it to LogonHostedExchangeMailbox – Dmitry Streblechenko Mar 04 '19 at 15:37
  • @Dimtry Streblechenko: If you are still there, the error I am getting is "There are no autodiscover servers in the AD for this address", for `RDOSession.LogonHostedExchangeMailbox`. – Kanu Priya Apr 02 '19 at 05:41
  • Can you post the full error? Redemption concatenates the errors from all potential autodiscover XML locations, and "There are no autodiscover servers in the AD for this address" is just one of them. – Dmitry Streblechenko Apr 02 '19 at 05:47
  • You are getting a 401 error, whcih means the credentials are wrong. – Dmitry Streblechenko Apr 02 '19 at 14:36
  • When I use different SMTP address in `RDOSession.LogonHostedExchangeMailbox` method, 401 error goes away, but autodiscover error remains. Do I need to add to add Autodiscover DNS record or something ? – Kanu Priya Apr 03 '19 at 04:50