ViReR.NeT | |
Home - Infos/Docs - Tools/Outils Code - Links/Liens - News - Download - Others/Autres Site map |
We run a qmail/vpopmail hosting environment for email, with a seperate device for outbound email access. We use authentication for all of our services, including SMTP, but as we virtual-host we need the full email address for authentication. By default Outlook only uses the username component (the part before the @) to authenticate, and we needed to change this behaviour.
Microsoft documents the autodiscovery functionality and XML format on their technet website at http://technet.microsoft.com/es-es/library/cc511504.aspx . A bit of close examination allowed us to see that Outlook sends an HTTP POST request that includes the target Email Address. We parse this using a simple Regular Expression, and then write it back into the response.
But how do we actually get Outlook to read this request? Well - it's not that hard. We create a SRV record for each mail domain that points to our secure server (_autodiscover._tcp IN SRV 0 100 443 secure.rwts.com.au.). Outlook then rewrites this to https://secure.rwts.com.au/autodiscover/autodiscover.xml when the user adds the email account. We have enabled mod_rewrite on our server to redirect requests into our autodiscover.php processor.
This is the our autodiscover.php script:
<?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");
?>
<?php 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>POP3</Type>
<Server>mail.rwts.com.au</Server>
<Port>110</Port>
<LoginName><?php echo $matches[1]; ?></LoginName>
<DomainRequired>off</DomainRequired>
<SPA>off</SPA>
<SSL>off</SSL>
<AuthRequired>on</AuthRequired>
<DomainRequired>off</DomainRequired>
</Protocol>
<Protocol>
<Type>IMAP</Type>
<Server>mail.rwts.com.au</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>SMTP</Type>
<Server>mx1.rwts.com.au</Server>
<Port>25</Port>
<DomainRequired>off</DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName>
<SPA>off</SPA>
<SSL>off</SSL>
<AuthRequired>on</AuthRequired>
<UsePOPAuth>on</UsePOPAuth>
<SMTPLast>on</SMTPLast>
</Protocol>
</Account>
</Response>
</Autodiscover>
This is our rewrite script (.htaccess):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ autodiscover.php [NC,L]