Guide for autodiscover

ikasp

Verified User
Joined
Jul 24, 2019
Messages
10
Location
Europé
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 [email protected] 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).
 
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.
 
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.
 
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.
 
I was implementing the autodiscover solution provided by DirectAdmin, but it didn't work. While debugging the issue I found out:

The request is not made to /autodiscover/autodiscover.xml but to /autodiscover/autodiscover.json

Log:
2.125.140.12 - - [20/Jun/2022:11:20:32 +0200] "GET /autodiscover/autodiscover.json?Email=[email protected]&Protocol=ActiveSync&RedirectCount=1 HTTP/1.1" 404 4881 "-" "OutlookMobileCloudService-Autodetect/1.0.0"

Does anybody know how to return a autodiscover config in json?
 
Back
Top