Autodiscover setting for outlook in Vesta CP

Autoconfiguration of email clients is handy when you are connecting with your own email provider. If you want your Outlook Client to autoconfigure email settings while configuring email@yourdomain.tld then you are in exactly right place.

We will walk you through some simple steps to set up autodiscovery in your server.

Before you begin you have to gather the following pieces of information:

  • Incoming mail server
    • Hostname
    • Protocol (IMAP or POP3)
    • Whether SSL is available or not
    • Port number (IMAP: 143, IMAPs: 993, POP3: 110, POP3s: 995)
    • Username format (full email address or just the local part)
    • Password mechanism (plain or encrypted)
  • Outgoing mail server
    • Hostname
    • Port number (most likely 587. If your SMTP server still only listens on port 25 many people will have troubles connecting as ISPs around the world started blocking this port. Enable the submission port 587, which on postfix for example is up by default)
    • Whether SSL or STARTTLS should be used
    • Username format
    • Password mechanism

 

Please note that the below steps can only be perform if you have Vesta CP root admin access. Simply, if you are setting it up in VPS or a Dedicated server. For setting it up in shared hosting please contact our highly efficient Server Administrators. If you have VPS server with us then we will set it up for free otherwise hire us with a minimal charge.

Lets do it. Follow the below steps :

  • Login to the Vesta admin account and create a subdomain under admin account. For example, discover.ditinex.online
  • Go to its public_html folder and create a new folder with name "Autodiscover". It is case sensitive so make sure to keep the capital A of Autodiscover.
  • Inside Autodiscover folder, create autodiscover.php and add the below code inside it. Make sure to change the default email and domain name in the code in line no 11 and 12. The code contains default ports and mailserver of VestaCP. Modify as per your need.
<?php

$data = file_get_contents("php://input");
preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $data, $matches);

$email = $matches[1];
$domain = explode('@',$email);
$domain = $domain[1];

if(empty($data)){
$email = 'admin@ditinex.online';
$domain = 'ditinex.online';
}

header("Content-Type: application/xml");
?>
<?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>imap.<?php echo $domain; ?></Server>
        <Port>993</Port>
        <DomainRequired>off</DomainRequired>
        <SPA>off</SPA>
        <SSL>on</SSL>
        <AuthRequired>on</AuthRequired>
        <LoginName><?php echo $email; ?></LoginName>
      </Protocol>
      <Protocol>
        <Type>SMTP</Type>
        <Server>smtp.<?php echo $domain; ?></Server>
        <Port>25</Port>
        <DomainRequired>off</DomainRequired>
        <SPA>off</SPA>
        <SSL>on</SSL>
        <AuthRequired>on</AuthRequired>
        <UsePOPAuth>on</UsePOPAuth>
        <SMTPLast>on</SMTPLast>
        <LoginName><?php echo $email; ?></LoginName>
      </Protocol>
      <Protocol>
        <Type>POP3</Type>
        <Server>pop.<?php echo $domain; ?></Server>
        <Port>995</Port>
        <DomainRequired>off</DomainRequired>
        <SPA>off</SPA>
        <SSL>on</SSL>
        <AuthRequired>on</AuthRequired>
        <LoginName><?php echo $email; ?></LoginName>
      </Protocol>
    </Account>
  </Response>
</Autodiscover>

  • Now create a .htaccess file in the same location with the below code inside it.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ autodiscover.php [NC,L]
  • Now access the file in browser and check whether it is working or not. It should show a XML output as below image.

vestacp autodiscover outlook

  • Your autodiscover configuration is ready. Now in order to discover email settings for your domain, you have to add a SRV record pointing to the discover subdomain. As example we are adding SRV record for our domain ditinex.online which will point to discover.ditinex.online.
  • Add the below SRV record with necessary changes.
Domain : maildomain.com

Record : _autodiscover._tcp

Type  : SRV

IP/Value : 10 443 discover.maildomain.com.

Priority : 10
  • Make sure SSL in installed in both the subdomain "discover" and the domain who you want to discover. In our case its "discover.ditinex.online" and "ditinex.online".
  • Now go to https://testconnectivity.microsoft.com and select Outlook Autodiscover and then test whether autodiscover connectivity is working or not. Check "Ignore Trust for SSL" option while testing.

In case of further issue, feel free to contact us. We will be more than happy to troubleshoot your issue.

Few additional tips :

To test the working of SRV record try the below command in terminal :

dig +short -t SRV _autodiscover._tcp.mydomain.com

To check working of Autodiscover.xml, create a file req.xml in /root with the below contents :

<?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>fred@emaildomain.com</EMailAddress>
  </Request>
</Autodiscover>

Make sure to change the email address with a valid email address to check.

Then install lwp-request if not installed already. The below command is for Ubuntu, google respective command for your OS. 

apt install libwww-perl

Then run the below command from within /root and the xml output will be return if everything works fine.

cat req.xml | lwp-request -m POST https://autodiscover.mymaildomain.com/autodiscover/autodiscover.xml
  • 32 Users Found This Useful
Was this answer helpful?