Autodiscover information for mail clients

General setup

Some mail clients will use a system called "Autodiscover" to figure out which settings to use for the pop/imap/smtp settings.

You can set this up rather easily if you'd like. It basically requires a subdomain and a SRV record. You can add the SRV record for any domain that you'd like to configure Autodiscover for. Using a global SSL certificate in Exim/Dovecot for the hostname would be a good way to ensure clients use the correct value and avoid SSL certificate errors.

Let's assume you're going to have your client with connect to for both IMAP and SMTP.

We'll create a subdomain called to store the XML.

  1. Set up a SRV record in the DNS zone: 3600 IN SRV 10 10 443
  1. Create the subdomain in DA, and add the following code into a file called autodiscover.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="">
   <Response xmlns="">
               <LoginName><?php echo $matches[1]; ?></LoginName>
               <LoginName><?php echo $matches[1]; ?></LoginName>
               <LoginName><?php echo $matches[1]; ?></LoginName>
  1. Install an SSL for It can be a commercial SSL or via Let's Encrypt. The SRV record is using port 443 for, so make sure you have a valid certificate configured for this subdomain.

If needed, you can set SMTP to use port 465, but you'd have to change the <Encryption> tag's data from TLS to SSL since the protocol is different on 465. Port 587 requires smtp-auth but skips some spam checks and uses STARTTLS to enable SSL. Port 465 is full SSL but clients might have issues sending if their IP/IP range is in an RBL.

  1. Lastly, we'll need to set up an .htaccess file so that any request to the subdomain results in the autodiscover.php being called. In the subdomain's DocumentRoot, create the .htaccess with this code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ autodiscover.php [NC,L]

Thunderbird special

Unlike Microsoft auto-detect, Thunderbird does a direct attempt on

This can be handled by creating a subdomain called "autoconfig", and in the web-area for this subdomain, create a folder called "mail", and inside this "mail" directory, create a file called config-v1.1.xml. A sample path in the File Manager might look like:


Inside this file, place the code:

<clientConfig version="1.1">
 <emailProvider id="">
   <incomingServer type="imap">
   <outgoingServer type="smtp">

Configure DNS for autodiscover

To apply DNS options for existing users (and enable by default for new domains), create a custom template first:

cd /usr/local/directadmin/data/templates/custom/
cp ../named.db .

Open named.db file and on the bottom of a file add:

_autodiscover._tcp.|DOMAIN|. 3600 IN SRV 10 10 443

Then rewrite zones for all domains:

echo "action=rewrite&value=named" >> /usr/local/directadmin/data/task.queue
/usr/local/directadmin/dataskq d80
Last Updated: