Knowledge Base

How Can We Help?

Autodiscover Information For Mail Clients in DirectAdmin

You are here:

Autodiscover is a system to determine which settings to utilize for the POP/IMAP/SMTP configurations, which enables the email client users to automatically configure their email address. This can be set up in DirectAdmin with the basic requirements: subdomain and an SRV record.

To use these settings, you need to add the SRV record on the desired client domain. If you have a global SSL certificate in exim/dovecot on your hostname, it is recommended to ensure that the clients use the correct value to avoid SSL certificate errors.

Let’s consider a scenario where you are connecting your clients to server.hostname.com with the clientdomain.com for both IMAP and SMTP. In order to begin, you need to create a subdomain called “autodiscover.hostname.com” to store the XML.

1) The first step is to set up the SRV record on the given client domain “clientdomain.com” in the DNS zone:

_autodiscover._tcp.clientdomain.com. 3600 IN SRV 10 10 443 autodiscover.hostname.com.

2) Next, you need to create the subdomain autodiscover.hostname.com in DirectAdmin, and then you can add the following code into a file called autodiscover.php:

<?php

//get raw POST data so we can extract the email address

$data = file_get_contents(“php://input”);

preg_match(“/<EMailAddress>(.*?)</EMailAddress>/”, $data, $matches);

//set Content-Type

header(“Content-Type: application/xml”);

echo ‘<?xml version=”1.0″ encoding=”utf-8″ ?>’; ?>

<Autodiscover xmlns=”http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006”>

<Response xmlns=”http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a”>

<Account>

<AccountType>email</AccountType>

<Action>settings</Action>

<Protocol>

<Type>IMAP</Type>

<Server>server.hostname.com</Server>

<Port>993</Port>

<DomainRequired>off</DomainRequired>

<LoginName><?php echo $matches[1]; ?></LoginName>

<SPA>off</SPA>

<SSL>on</SSL>

<AuthRequired>on</AuthRequired>

</Protocol>

<Protocol>

<Type>POP3</Type>

<Server>server.hostname.com</Server>

<Port>995</Port>

<DomainRequired>off</DomainRequired>

<LoginName><?php echo $matches[1]; ?></LoginName>

<SPA>off</SPA>

<SSL>on</SSL>

<AuthRequired>on</AuthRequired>

</Protocol>

<Protocol>

<Type>SMTP</Type>

<Server>server.hostname.com</Server>

<Port>587</Port>

<DomainRequired>off</DomainRequired>

<LoginName><?php echo $matches[1]; ?></LoginName>

<SPA>off</SPA>

<Encryption>TLS</Encryption>

<AuthRequired>on</AuthRequired>

<UsePOPAuth>off</UsePOPAuth>

<SMTPLast>off</SMTPLast>

</Protocol>

</Account>

</Response>

</Autodiscover>

 The SRV record should always use port 443 for autodiscover.hostname.com, so make sure to have a valid certificate set up for this subdomain. You can check this by entering the domain on https://www.sslshopper.com/ssl-checker.html or try accessing it on a browser with https://autodiscover.hostname.com

3) Finally, we need to set up a .htaccess hidden file so that we can redirect any requests to the required subdomain, like autodiscover.hostname.com, to the autodiscover.php script. Add the following lines to the .htaccess file under the subdomain DocumentRoot:

RewriteEngine On

RewriteCond %REQUEST_FILENAME -s [OR]

RewriteCond %REQUEST_FILENAME -l [OR]

RewriteCond %REQUEST_FILENAME -d

RewriteRule ^.*$ – [NC,L]

RewriteRule ^.*$ autodiscover.php [NC,L]

If you need further assistance, please reach out to our support department.

Leave a Comment