autodiscover not working?

agaitan026

Verified User
Joined
Mar 24, 2021
Messages
42
Hi i followed this guide https://help.directadmin.com/item.php?id=661 but still autodiscover not working i did create a .htaccess inside subdomain and put

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ autodiscover.php [NC,L]

but im not sure if i have mod rewrite enabled


[root@directadmin custombuild]# /usr/sbin/httpd -l | grep mod_rewrite
mod_rewrite.c
 
followed this https://docs.directadmin.com/other-hosting-services/email/autodiscover and getting thins:

[Tue Mar 30 08:18:00.841945 2021] [autoindex:error] [pid 62340:tid 140246920754944] [client 192.168.1.1:18944] AH01276: Cannot serve directory /home/dbsnetwo/domains/mydomain.net/private_html/autodiscover/: No matching DirectoryIndex (index.html,index.htm,index.shtml,index.php,index.phtml) found, and server-generated directory index forbidden by Options directive
[Tue Mar 30 08:18:00.896351 2021] [proxy_fcgi:error] [pid 62340:tid 140246920754944] [client 192.168.1.1:18944] AH01071: Got error 'PHP message: PHP Notice: Undefined offset: 1 in /home/dbsnetwo/domains/mydomain.net/public_html/autodiscover/autodiscover.php on line 20PHP message: PHP Notice: Undefined offset: 1 in /home/dbsnetwo/domains/mydomain.net/public_html/autodiscover/autodiscover.php on line 30PHP message: PHP Notice: Undefined offset: 1 in /home/dbsnetwo/domains/mydomain.net/public_html/autodiscover/autodiscover.php on line 40', referer: https://autodiscover.mydomain.net/

my full autodiscover.php:

XML:
<?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>mail.mydomain.net</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>mail.mydomain.net</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>mail.mydomain.net</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>
 
Last edited:
What email client are you testing with Outlook or thunderbird?

You set up the SRV records and its been at least server hours since you did it correct?
 
What email client are you testing with Outlook or thunderbird?

You set up the SRV records and its been at least server hours since you did it correct?

Outlook, yes srv records

1617111356751.png
have been passed 24 hours, but why im getting that PHP error? for this task according to the documentation:

  1. Lastly, we'll need to set up an .htaccess file so that any request to the autodiscover.dbsnetwork.net subdomain results in the autodiscover.php being called. In the subdomain's DocumentRoot, create the .htaccess with this code:
 
but why im getting that PHP error?
Because there is an error in the php script... Probably $matches is empty. If this is when you did a request in your browser it's normal the variable is empty because you're not posting any information on that manual request.
 
I was running into the same situation yesterday, also trying to get autodiscover working, and only got it to work after I started tinkering with with rules in the .htaccess file

It started working for me when I changed the fore-last line in the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ autodiscover.php [NC,L]

When I changed
RewriteRule ^.*$ - [NC,L]
to
RewriteRule ^.*$ - [NC]

the last rule also kicked in, and it started working for me.
Now, I am not very proficient at .htaccess rules, but after reading up on this, I read somewhere that the 'L' in these rules was supposed to mean it was the last rule and things should stop with the 'L'.
Could be, could not be, I don't know. I only know for sure that it made the difference for me.
And it could make the differenence for others ..?
 
Back
Top