Absolutely love this idea!
I just had a play with AI and came up with some parts, the issue is going to be generating the needed xml file per users website/domain, as far as I know and could search, we don't have a hook on website/domain creation... so this will need injecting via cron or something.
Or maybe monitor the orchd logs for a domain/website creation and then perform a check/patch for this php generator file?
SRV record template:
`dns:
- type: SRV
name: autodiscover.tcp
value: "10 10 443 mail.$$origin$$"
- type: SRV
name: submission.tcp
value: "10 10 587 mail.$$origin$$"
- type: SRV
name: imap.tcp
value: "10 10 993 mail.$$origin$$"
- type: SRV
name: pop3.tcp
value: "10 10 995 mail.$$origin$$"
- type: CNAME
name: mail
value: "mail.$$origin$$"`
xml generator:
autodiscover.php
<?php
// Get the full host (e.g., autodiscover.example.com)
$host = $_SERVER['HTTP_HOST'];
// Extract the base domain (e.g., example.com)
$hostParts = explode('.', $host);
if (count($hostParts) > 2) {
$baseDomain = implode('.', array_slice($hostParts, -2));
} else {
$baseDomain = $host;
}
// Path to the autodiscover.xml file
$filePath = __DIR__ . '/autodiscover.xml';
// Check if the autodiscover.xml file exists
if (!file_exists($filePath)) {
// Generate the XML content dynamically
$xmlContent = '<?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.' . $baseDomain . '</Server>
<Port>993</Port>
<DomainRequired>off</DomainRequired>
<LoginName>%EMAILADDRESS%</LoginName>
<SPA>off</SPA>
<SSL>on</SSL>
<AuthRequired>on</AuthRequired>
</Protocol>
<Protocol>
<Type>POP3</Type>
<Server>mail.' . $baseDomain . '</Server>
<Port>995</Port>
<DomainRequired>off</DomainRequired>
<LoginName>%EMAILADDRESS%</LoginName>
<SPA>off</SPA>
<SSL>on</SSL>
<AuthRequired>on</AuthRequired>
</Protocol>
<Protocol>
<Type>SMTP</Type>
<Server>mail.' . $baseDomain . '</Server>
<Port>587</Port>
<DomainRequired>off</DomainRequired>
<LoginName>%EMAILADDRESS%</LoginName>
<SPA>off</SPA>
<Encryption>TLS</Encryption>
<AuthRequired>on</AuthRequired>
<UsePOPAuth>off</UsePOPAuth>
<SMTPLast>off</SMTPLast>
</Protocol>
</Account>
</Response>
</Autodiscover>';
// Save the XML content to a file
file_put_contents($filePath, $xmlContent);
}
// Serve the autodiscover.xml file
header("Content-Type: application/xml");
readfile($filePath);
exit;
?>```
if we also patch the .htacess like this, it should handle the file, or create and serve it.
```RewriteEngine On
# Route all requests for autodiscover.xml to autodiscover.php
RewriteRule ^autodiscover/autodiscover.xml$ autodiscover.php [L]```
it will need to be detected here: Access the autodiscover service via:
https://autodiscover.example.com/autodiscover/autodiscover.xml
For the people using a 3rd party whmcs/blesta etc... they could poll the enhance api to help with a little more automation upon account creation in their pipeline.
Just an idea, pick and choose what might or might not work. I need to jump back on to something else, so hoping some else can test/run with this a little more. 🙂