1

Im writing a Service-Application that should monitor one or more ExchangeMailboxes for incoming Mails to perform some action with those.
The Service will run in different environments, which means i need to support Outlook 2010 to 2019.

How can i reliably Logon to a Session from a Service-Application no matter the Outlookversion?

I have the following code that works for Outlook 2010 but not 2016. The ExchangeServer is the same and using version 2010.

for MailboxName in MailboxesToMonitor do
begin
  Session := RedemptionLoader.new_RDOSession;
  Session.LogonExchangeMailbox(MailboxName, 'ExchangeServerName'); // works for 2010, but not 2016
  DefaultStore := Session .Stores.DefaultStore;
  if (LDefaultStore.StoreKind in [skPrimaryExchangeMailbox, skDelegateExchangeMailbox]) then
  begin
    MailboxStore := TRDOExchangeMailBoxStore.Create(Self);
    try
      MailboxStore.ConnectTo(DefaultStore as IRDOExchangeMailboxStore);
      MailboxStore.OnNewMail := RDOStoreOnNewMail;
    except
      LMailboxStore.Free;
      raise;
    end;
    Sessions.Add(Session);
  end;
end;
  • Session.LogonExchangeMailbox throws a MAPI_E_UNKNOWN_FLAGS error with Outlook 2016 installed.
  • Session.Logon didnt work in a ServiceApplication.
  • Session.LogonHostedExchangeMailbox throws:
    1. EOleSysError: Expected HTTP_STATUS_REDIRECT, recieved 403
    2. EIdDnsResolverError: DNS Server Reports Query Name Error
    3. EHTTPError: HTTP error 401 from https://autodiscover.domain.com/autodiscover/autodiscover.xml
    4. EOleSysError: GetAutodiscoverUrlFromDns error: DNS lookup error using xx.xx.xx.xx: DNS Server Reports Query Name Error
    5. EOleSysError: GetAutodiscoverForEmailAddress: There are no autodiscover servers in the AD for this address
yberk
  • 78
  • 1
  • 7
  • 1
    If you want an outlook independend working setup, use EWS API, here is [an example with powershell](https://seanonit.wordpress.com/2014/10/29/using-powershell-and-ews-to-monitor-a-mailbox/) – whosrdaddy May 21 '19 at 12:20
  • Error 401 means the credentials are wrong. What do you pass for the first and second paraeters? – Dmitry Streblechenko May 23 '19 at 21:45
  • good point, i tried `Session.LogonHostedExchangeMailbox('me@company.com', 'me@company.com', '');` and that didnt work, it did work though with using 'Domain\Username' as `UserName`parameter, so i needed to use *NTLM authentication*. Is there a way to check which authentication-method is needed beforehand or do i just need to try and see what works, if i dont know what is used? – yberk May 24 '19 at 07:36

1 Answers1

3

Keep in mind that LogonExchangeMailbox connects to the server in the old RPC mode, which the latest versions of Exchange Server no longer support.

You need to use LogonHostedExchangeMailbox for Exchange 2013 / 2016 / 2019 - it connects in the PRC-over-HTTP or MAPI-over-HTTP mode. You will need to have at least Outlook 2010 SP2, 2013 SP1, or 2016 / 2019 for LogonHostedExchangeMailbox to work.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • In the current environment Exchange 2010 is used, does that mean `LogonExchangeMailbox` is the correct way here? This works on a machine with Outlook 2010 but not on a machine with Outlook 2016 – yberk May 22 '19 at 09:11
  • LogonExchangeMailbox should still work... Does LogonHostedExchangeMailbox work for your Exchange 2010 server? – Dmitry Streblechenko May 22 '19 at 15:04
  • `LogonHostedExchangeMailbox` does not work for my Exchange 2010 server, please see the edited question for the errors im getting. – yberk May 23 '19 at 12:20