WinBlogs

Some techy stuff and occasional verbose ramblings :D

Servers, Windows and Powershell

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: 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:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Autodiscover xmlns=”http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006″>
<Request>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
<EMailAddress>[email protected]</EMailAddress>
</Request>
</Autodiscover>

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:

1.

<rule name=”Thunderbird” stopProcessing=”true”>
<match url=”^(.*)mail/config-v1.1.xml” />
<action type=”Rewrite” url=”thunderbird.php” />
</rule>

2.
<rule name=”Outlook” stopProcessing=”true”>
<match url=”^(.*)autodiscover/autodiscover1.xml” />
<action type=”Rewrite” url=”outlook.php” />
</rule>

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.

 

13 Comments

  1. daren

    Nice job!

    What about your Apple Mail script, have you succeed in finishing it?

  2. Erik

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

  3. Alesandro Slepčević

    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.

  4. Csaba

    script for AppleMail?

  5. Endo

    Hello. So… AppleMail script ready and works?

  6. nico

    heyho,

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

    is there any progess?

  7. Stiwi Courage

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

  8. oskar

    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.

  9. Alesandro Slepčević

    Yes, I forgot to write that. Thank you for the update.

  10. Alesandro Slepčević

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

  11. Alesandro Slepčević

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

  12. Alesandro Slepčević

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

  13. Alesandro Slepčević

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Theme by Anders Norén