Since I work in a big web hosting company, we have A LOT of phone calls and tickets from people who dont know how you set up their mail client ( mostly Outlook and Thunderbird ).
Since I got fed up with it, I decided to explore how autodiscover for Microsoft Outlook and Mozilla Thunderbird works.
Creating a script for Thunderbird was pretty much very simple, but creating a script for Outlook took a bit more effort and “reverse engineering” 🙂
I will not go into details about the script for Thunderbird, since everything is explained here: https://developer.mozilla.org/en-US/docs/Thunderbird/Autoconfiguration/FileFormat/HowTo
Lets focus on the autodiscover.xml generator for Outlook.
After couple of hours of searching I found an information about the POST request that Outlook sends to the autodiscover server on autodiscover.domain.tld/autodiscover/autodiscover.xml .
This is the request:
So, what do we need to do here? For starters, we need to extract the email address from the POST request. Second step is to extract the domain name from that email address and use that data to generate autodiscover.xml file that Outlook can understand.
In order for out script to work, we need three prerequisites!
1. Create a CNAME record called “autodiscover” and point it to the server where you keep the scripts for generating XML files.
2. Create a rewrite rule that will redirect the request to the correct script.
3. Beer or coffee
Rules that you need to add to your web.config file or .htaccess file on the autodiscover server are:
Please note that you will most probably need to modify the rewrite rule if you’re using a linux server.
Lets explain these rules. Since Thunderbird searches for configuration file on domain autodiscover.domain.tld/mail/config-v1.1.xml , we need to redirect those requests to our script called thunderbird.php .
Pretty much, the same thing happens with Outlook. Like we said before, Outlook looks for autodiscover.xml file on domain : autodiscover.domain.tld/autodiscover/autodiscover.xml . We redirect those requests to outlook.php script that generates the XML file.
Funny issue I had with Outlook is that even though I was getting a valid XML output, Outlook just didnt want to load the settings. After some more Google, cursing and coffee I found the information which said that the script needs to return code 405 as a response, not 200 OK as EVERYONE would expect! Way to go Microsoft! 😀
When you open the scripts, you can modify your settings accordingly ( mail ports, SSL, mail server address, etc…)
Download link for Thunderbird script
Download link for Outlook script.
If you have any question or suggestions, just holla at me!
Bye, bye! Alesandro.