Guide for autodiscover

ikasp

Verified User
Joined
Jul 24, 2019
Messages
7
The email client Microsoft Outlook is supposed to use autodiscover for auto configuration, amongst others described in https://docs.microsoft.com/en-us/previous-versions/office/office-2010/cc511507(v=office.14).

Our solution is based on the solution given by https://github.com/smartlyway/email-autoconfig-php with some minor tweaks.

With our solution autodiscover is put on each domain, and hence there is no need for a DNS SRV record. From the Microsoft article above:

Autodiscover in Outlook 2010 is an XML file that is put in one of two locations, based on the domain name provided by the user. For the Internet, Autodiscover relies on the Domain Name System (DNS) to find the XML file. The XML file location is based on the e-mail address that the user provides. For example, if barbara@contoso.com is entered as the user’s e-mail address, Outlook 2010 looks for the XML file in the following locations and in the following order:

1. https://contoso.com/autodiscover/autodiscover.xml

2. https://autodiscover.contoso.com/autodiscover/autodiscover.xml

If your company also has a Web site at the root domain (for example, contoso.com), the second option (the Autodiscover “host (A) resource record” solution) lets you run the Web server and the Autodiscover file or service on separate servers. For smaller companies, the additional management of having separate DNS records can be ignored, and a single server can run both the Web site and the Autodiscover service (for example, the option 1 listed previously).
We have chosen option 1 above.

Start to create Autodiscover.xml. Since data will be posted to it, we use the trick to create Autodiscover.xml as a directory and put an index.php file there.

Code:
mkdir -p /var/www/html/Autodiscover/Autodiscover.xml
cd /var/www/html/Autodiscover/Autodiscover.xml
vi index.php
Put the following content to index.php

PHP:
<?php
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

$raw = file_get_contents('php://input');
$matches = array();
preg_match('/<EMailAddress>(.*)<\/EMailAddress>/', $raw, $matches);
$email = $matches[1];

if (!filter_var($email,FILTER_VALIDATE_EMAIL)){
        // plonk, no remorse
        die();
}

list($user,$domain) = preg_split("/@/",$email,2);

header('Content-Type: application/xml');
?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
  <Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
    <User>
      <DisplayName><?=$email?></DisplayName>
    </User>
    <Account>
      <AccountType>email</AccountType>
      <Action>settings</Action>
      <Protocol>
        <Type>IMAP</Type>
        <Server>mail.<?=$domain?></Server>
        <Port>993</Port>
        <DomainRequired>off</DomainRequired>
        <SPA>off</SPA>
        <SSL>on</SSL>
        <AuthRequired>on</AuthRequired>
        <LoginName><?=$email?></LoginName>
      </Protocol>
      <Protocol>
        <Type>SMTP</Type>
        <Server>mail.<?=$domain?></Server>
        <Port>587</Port>
        <DomainRequired>off</DomainRequired>
        <SPA>off</SPA>
        <SSL>on</SSL>
        <AuthRequired>on</AuthRequired>
        <LoginName><?=$email?></LoginName>
      </Protocol>
    </Account>
  </Response>
</Autodiscover>
Set ownership

Code:
cd /var/www/html/Autodiscover
chown -R webapps.webapps .
Create alias with custombuild

Code:
cd /usr/local/directadmin/custombuild
echo 'Autodiscover/Autodiscover.xml=Autodiscover/Autodiscover.xml' >> custom/webapps.list
./build rewrite_confs
Now to test this, create an email account on the server and go to
https://testconnectivity.microsoft.com/ to test it, see this image https://xxa.se/i/10n123m.png

Our implementation did pass the test. But, when I tested with the latest Outlook version on both Windows and MacOS, it never used autodiscover. Outlook did however find the proper settings very fast. It decided to use SSL on 465 and 993. Our TB autoconfig, thread Thunderbird:Autoconfiguration , has set TLS as the preferred settings. Hence Outlook does not use that method either to decide the settings.

So, the bottom line, I am not sure what the value is to implement autodiscovery. I guess it used for active sync, but we do not offer it and the xml scheme is very different from the above (hence activesync tests will fail).
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,934
Location
GMT +7.00
Hello,

The last time I've tried the newest Office 365 I've found out it very tricky to get working with a custom hosted autodiscover. All tests are passing fine, and still in certain cases autodiscover failed for some domains. In logs I found IPs from Microsoft Network, so it seems they somehow proxy requests and it add some difficulties.

So in your case it might be not that XML file is wrong, you might need to dig it further and check logs.
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,934
Location
GMT +7.00
That's what I faced too, I did not find any logic in new software versions from Microsoft. And their documentation I've found does not enlighten it.
 

thomaz767

New member
Joined
Oct 13, 2019
Messages
2
The email client Microsoft Outlook is supposed to use autodiscover for auto configuration, amongst others described
I was facing some problems with other email clients, and it was mainly a huge problem for live mail, when I was using it for my work purposes. When I've transferred to Outlook, by using outlooktransfer app, I thought that I'm not gonna see these problems anymore, but still face with it time to time. By the way, it's been pretty easy to transfer all my emails from one client to another.
 
Top