hMailServer, IIS 8.5 and Autodiscover – Part 2

hMailServer, IIS 8.5 and Autodiscover – Part 2

[lastupdated]

Oh good to see you back. My guess is, that have you installed all of the prerequisites mentioned in the first article. If not, I really don’t know what you’re doing here. If you’re here because Google promised you ice-cream and you’re interested in using an Apache  for the autodiscover, check out Kernel-Error.de (German). This article also helped me greatly improve my understanding on how the process works, thanks for that!

So far you have:

  • A working hMailServer
  • A working IIS with working PHP _and_ HTTPS properly configured (and tested)

Outlook is – according to the Technet article from Part 1 – trying to reach several destinations based on the address you enter. Both point to the subfolder /Autodiscover. So create a virtual directory or create a folder by that name within the sites root. There you will need a PHP file, which handles the XML-POST and returns a proper XML. Don’t know what the PHP script should do? Luckily there is a GitHub for that. This is the essential part of this tutorial, because this autodiscover.php is exactly what we need. All that’s left now is customize the file to your server (again, check the Technet article) and tell the IIS how to handle the request.

First we have to tell our IIS that it has to accept the POST of the XML. We do that by adding a handler to the web site of your choice.

XML Handler Final

You may need to change the verbs to “GET,POST” and change the “Access” to a higher level until it is working. For my testing environment I had to change this up to “script”. I wouldn’t recommend doing that unless it’s an intra company request. Even then, this may be a potential risk. The PHP we created will use the posted .xml from Outlook, extract the <emailadress> from the XML and add it as the <loginname> value.

URL-RewriteThe last thing to do is an URL Rewrite. The XML file is now accepted by the IIS, but doesn’t know what to do with it. We can create an URL Rewrite that does just that. You can either use my web.config or create your own via the IIS Wizard. Just create a blank rule and basically enter the necessary parts from the code below.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Autodiscover XML to PHP" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="*autodiscover.xml" />
                    <action type="Rewrite" url="{R:1}autodiscover.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

What you need now is a tool to test if your autodiscover is working. Microsoft created a special website doing that for you – as long as you agree on giving them credentials. This will check if the discover process is working. Since we have our own mail server and no user limitation I recommend creating a test account.

2015-01-24 18_37_26-Microsoft Remote Connectivity AnalyzerFill out the form and hit “Perform Test” – the result should look something like this:

2015-01-24 18_45_58-Microsoft Remote Connectivity AnalyzerSo, now you (should) have a working Autodiscover for Outlook! Congrats!

ToDo: Autodiscover for ActiveSync. I will put a link here, as soon as the article is ready. Going through some old tech articles, this seems out of date by todays standards. So this won’t happen.

Leave a Reply