Autodiscover with SmarterMail…or any other mail server

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:

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:
[email protected]

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.


15 thoughts on “Autodiscover with SmarterMail…or any other mail server

  1. Have you succeeded with Apple Mail? I am looking into the same thing and it seems a bit complicated.

  2. Yes, I have succeded with AppleMail. I just need to finish the part of the script that automatically creates a setup file. When I do it manually everything works. Will update the ticket one I finish it.

  3. heyho,

    i’m also struggling around with a “autodiscover”-feature for apple mail.

    is there any progess?

  4. Looking forward to the Apple mail script, please post when ready, og leave me a email and perhaps I can finish it for you. 🙂

  5. You don’t mention the need of a valid ssl cert for the outlook autodiscover host. But it doesn’t work without any ssl, or does it? Thank you.

  6. Drop me an email at slepi99 (a) and I will send you the code and explanation how to finish it.

  7. Drop me an email at slepi99 (a) and I will send you the code and explanation how to finish it.

  8. Drop me an email at slepi99 (a) and I will send you the code and explanation how to finish it.

  9. Drop me an email at slepi99 (a) and I will send you the code and explanation how to finish it.

  10. Hi,
    Just a quick note to give an example of redirects for Apache on *nix:

    RewriteEngine On
    RewriteRule ^(.*)mail/config-v1.1.xml thunderbird.php [NC]
    RewriteRule ^(.*)autodiscover/autodiscover.xml outlook.php [NC]

    I added the “no case” directive ([NC]) because Microsoft’s own checker uses capital As for “Autodiscover”, even though Outlook does not. GG Microsoft.
    The tool is here: (it works for non-exchange servers too)

    Additionally, not sure if the rules have changed or if my version of Office is different to yours, but I don’t need to return 405 to make Outlook accept my autodiscover XML. YMMV.

    You have a typo for your Thunderbird directions – you list:
    But Thunderbird doesn’t look there, it checks:

    Finally, a small bug in your regular expression for outlook.php:
    Pattern matching: /[A-Za-z0-9_-][email protected][A-Za-z0-9_-]+.([A-Za-z0-9_-][A-Za-z0-9_]+)/
    …will work fine, as long as your email uses a single tld: .com .net. org etc
    It will *not* work for, etc – it only matches the first part.
    I am a lazy man by nature, and ended up stealing the regular expression from this old guide:

    ie: /(.*)/
    Obviously, you would use matches[1] to recover the full address with that pattern.

    Thanks for the blog post – it was most useful for setting up our autoconfig/autodiscover services!

  11. Hi J.
    Thank you very much for your comment and rewrite rules for Apache.
    I actually did grab a regex string from some website ( also lazy 🙂 ), but I didn’t check for,, etc… 🙂
    I’ll update the post ASAP.
    I’m sure that my version of Outlook required a 405 response code, since that was the thing that was bugging me for quite some time ( will try to digout the documentation to check what version of Outlook I was using ).

    Cheers, Alesandro .

Leave a Comment

Your email address will not be published. Required fields are marked *