. // // SPDX-License-Identifier: LGPL-3.0-or-later // Outlook autoconfiguration described at: // https://docs.microsoft.com/en-us/previous-versions/office/office-2010/cc511507(v=office.14) // // Should be installed at: // https://[domain]/autodiscover/autodiscover.xml // https://autodiscover.[domain]/autodiscover/autodiscover.xml $request_path = explode("?", $_SERVER['REQUEST_URI'])[0]; if ($request_path == "/autodiscover/autodiscover.xml" && preg_match('/^autodiscover\.(.*)$/', $_SERVER['HTTP_HOST'], $matches)) { $domain = $matches[1]; } else if ($request_path == "/autodiscover/autodiscover.xml") { $domain = $_SERVER['HTTP_HOST']; } else { http_response_code(500); header('Content-Type: text/plain'); echo "Unable to determine email domain from //".$_SERVER['HTTP_HOST'].$request_path; exit(1); } $IMAP = dns_get_record("_imaps._tcp.".$domain, DNS_SRV) ?: dns_get_record("_imap._tcp.".$domain, DNS_SRV); $SMTP = dns_get_record("_submission._tcp.".$domain, DNS_SRV); if (!$IMAP || !$SMTP) { http_response_code(500); header('Content-Type: text/plain'); if (!$IMAP) { echo "Missing/unavailable IMAP(S) SRV record for ".$domain; } if (!$SMTP) { echo "Missing/unavailable Submission SRV record for ".$domain; } exit(1); } $sitename = getenv("EMAIL_SITENAME") ?: $domain; $shortname = getenv("EMAIL_SHORTNAME") ?: $sitename; if (($xml = simplexml_load_string(file_get_contents('php://input'))) != false && $xml->registerXPathNamespace('a', 'http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006') && ($emails = $xml->xpath("/a:Autodiscover/a:Request/a:EMailAddress")) != false && $emails != null && count($emails) == 1 && preg_match("/^([^@]*)@([^@]*)$/", $emails[0], $parts)) { $login = $parts[1]; } else { $login = ""; } header('Content-Type: application/xml'); ?> email settings IMAP off off on on SMTP off off on on