Autodiscover Information For Mail Clients in DirectAdmin

Last modified: July 26, 2020
You are here:
Estimated reading time: 1 min

Autodiscover is a system to figure out which settings to use for the POP/IMAP/SMTP settings, that allows the mail client users to configure their email address automatically. We can set up this in DirectAdmin with basic requirement: subdomain and an SRV record.

You can add the SRV record on which domain you wish to use these settings for. If you have any global SSL certificate in exim/dovecot for your hostname, it will be better to make sure the clients use the correct value. Hence they did not get SSL certificate errors.

Let’s suspect that you are connecting your clients to server.hostname.com with clientdomain.com for both IMAP and SMTP. Then first of all need to create a subdomain called ” autodiscover.hostname.com ” to store the  XML.

1) Need to setup SRV record on the mentioned client domains “clientdomain.com” DNS zone:

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

2) Next, need to create the subdomain autodiscover.hostname.com in Directadmin, then can we add the follwing 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>

 SRV record always using port 443 for autodiscover.hostname.com, So make sure you have got a valid certificate setup for this subdomain. You can check this by entering the domain on https://www.sslshopper.com/ssl-checker.html or can try to access it on a browser with https://autodiscover.hostname.com

3) Finally, we will need to set up a .htaccess hidden file so that we can trace any request to the needed subdomain like autodiscover.hostname.com results in the autodiscover.php being called. We need to 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 any further help, please do reach our support department.

Was this article helpful?
Dislike 0
Views: 12