First, you need to set up DNS for your domain:

  *   CNAME of autoconfig for your web server
  *   CNAME of autodiscover for your web server
  *   SRV record of _autodiscover._tcp
So it should look like:
_autodiscover._tcp      SRV  10 0 443      webmail.domain.com.
autoconfig              CNAME webmail.domain.com.
autodiscover            CNAME webmail.domain.com.

On the web server you then need

  *   enable PHP
  *   a couple of aliases:
Alias /autodiscover/autodiscover.xml "/var/www/html/autodiscover.php"
Alias /Autodiscover/Autodiscover.xml "/var/www/html/autodiscover.php"
Alias /AutoDiscover/AutoDiscover.xml "/var/www/html/autodiscover.php"
Alias /ios "/var/www/html/mailsetup.php"

  *   then those autodiscover.php and mailsetup.php files
  *   and this mail/config-v1.1.xml:
<?xml version="1.0" encoding="UTF-8"?>
<clientConfig version="1.1">
    <emailProvider id=" domain.com">
        <domain>domain.com</domain>
        <displayName>eMail @ domain.com </displayName>
        <displayShortName>domain.com</displayShortName>
        <incomingServer type="imap">
            <hostname>webmail.domain.com</hostname>
            <port>993</port>
            <socketType>SSL</socketType>
            <authentication>password-cleartext</authentication>
            <username>%EMAILLOCALPART%</username>
        </incomingServer>
        <outgoingServer type="smtp">
            <hostname>webmail.domain.com</hostname>
            <port>465</port>
            <socketType>SSL</socketType>
            <authentication>password-cleartext</authentication>
            <username>%EMAILLOCALPART%</username>
        </outgoingServer>
        <documentation 
url=https://webmail.domain.com<https://webmail.domain.com%20>>
            <descr lang="de">WebMail-Interface zu domain.com</descr>
            <descr lang="en">WebMail interface for domain.com</descr>
        </documentation>
    </emailProvider>
</clientConfig>

The autodiscover.php is a bit lengthy:

<?php

// For other supported protocols and more protocol settings, see:
//  http://technet.microsoft.com/en-us/library/cc511507.aspx

// Get contents of request made to Autodiscover.
$request = file_get_contents("php://input");
preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $request, 
$email_address);
preg_match("/\<EMailAddress\>(.*?)@(.*?)\<\/EMailAddress\>/", $request, 
$email_name);

/*** Begin Configuration ***/

// ActiveSync URL.
$_CONFIG['MobileSync']['Url'] = 
https://webmail.domain.com/Microsoft-Server-ActiveSync;

// IMAP configuration settings.
$_CONFIG['IMAP']['Server'] = "webmail.domain.com";
$_CONFIG['IMAP']['Port'] = "993";
$_CONFIG['IMAP']['SSL'] = "on";
$_CONFIG['IMAP']['SPA'] = "off";
$_CONFIG['IMAP']['AuthRequired'] = "on";
$_CONFIG['IMAP']['DomainRequired'] = "off";
$_CONFIG['IMAP']['LoginName'] = $email_name[1];

// SMTP configuration settings.
$_CONFIG['SMTP']['Server'] = "webmail.domain.com";
$_CONFIG['SMTP']['Port'] = "465";
$_CONFIG['SMTP']['SSL'] = "on";
$_CONFIG['SMTP']['SPA'] = "off";
$_CONFIG['SMTP']['AuthRequired'] = "on";
$_CONFIG['SMTP']['DomainRequired'] = "off";
$_CONFIG['SMTP']['LoginName'] = $email_name[1];

/*** End Configuration ***/

// XML document heading.
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

// Get the schema from the request.
preg_match("/\<AcceptableResponseSchema\>(.*?)\<\/AcceptableResponseSchema\>/", 
$request, $schema);

// Determine the type of device requesting Autodiscover.
if (preg_match("/\/mobilesync\//", $schema[1]))
{
        // Mobile device.
        ?>
                <Autodiscover 
xmlns=http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006>
                        <Response xmlns="<?php echo $schema[1]; ?>">
                                <Culture>de:de</Culture>
                                <User>
                                        <DisplayName><?php echo 
$email_address[1]; ?></DisplayName>
                                        <EMailAddress><?php echo 
$email_address[1]; ?></EMailAddress>
                                </User>
                                <Action>
                                        <Settings>
                                                <Server>
                                                        <Type>MobileSync</Type>
                                                        <Url><?php echo 
$_CONFIG['MobileSync']['Url']; ?></Url>
                                                        <Name><?php echo 
$_CONFIG['MobileSync']['Url']; ?></Name>
                                                </Server>
                                        </Settings>
                                </Action>
                        </Response>
                </Autodiscover>
        <?php
}
else if (preg_match("/\/outlook\//", $schema[1]))
{
        // MUA (mail client).
        ?>
                <Autodiscover 
xmlns=http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006>
                        <Response xmlns="<?php echo $schema[1]; ?>">
                                <Account>
                                        <AccountType>email</AccountType>
                                <Action>settings</Action>
                        <?php
                                        // Loop through each configured 
protocol.
                                        while(list($protocol, $settings) = 
each($_CONFIG))
                                        {
                                                // Skip ActiveSync protocol.
                                                if ($protocol == "MobileSync") 
continue;
                                        ?>
                                                <Protocol>
                                                        <Type><?php echo 
$protocol; ?></Type>
                                        <?php
                                                // Loop through each setting 
for this protocol.
                                                while(list($setting, $value) = 
each($settings))
                                                {
                                                        echo 
"\t\t\t\t\t\t\t<$setting>$value</$setting>\n";
                                                }
                                        ?>
                                                </Protocol>
                                        <?php
                                        }
                                ?>
                                </Account>
                        </Response>
                </Autodiscover>
        <?php
}
else
{
        // Unknown.
        list($usec, $sec) = explode(' ', microtime());
        ?>
                <Autodiscover 
xmlns=http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006>
                        <Response>
                                <Error Time="<?php echo date('H:i:s', $sec) . 
substr($usec, 0, strlen($usec) - 2); ?>" Id="2477272013">
                                        <ErrorCode>600</ErrorCode>
                                        <Message>Invalid Request</Message>
                                        <DebugData />
                                </Error>
                        </Response>
                </Autodiscover>
        <?php
}
?>

And the mailsetup.php for iOS devices:

<?php if (isset($_REQUEST['name'])):?>
<?php

$username = strtolower($_REQUEST['name']);
$conf = file_get_contents('/var/www/html/mailsetup.mobileconfig');
$conf = str_replace('%EMAIL%', $username . '@domain.com', $conf);
$conf = str_replace('%USERNAME%', $username, $conf);

$timestamp = microtime(true);
$filehandle = fopen("/var/www/html/apple/$timestamp", "w");
fwrite($filehandle, $conf);
fclose($filehandle);

$cmdline = "/usr/bin/openssl smime -sign -in /var/www/html/apple/$timestamp 
-out /var/www/html/apple/$timestamp.signed -signer /etc/pki/dovecot/dovecot.cer 
-inkey /etc/pki/dovecot/private/dovecot.pem -certfile 
/etc/pki/dovecot/intermediate.cer -nodetach -outform der";
$output = exec($cmdline);

header('Content-type: application/x-apple-aspen-config; charset=utf-8');
header('Content-Disposition: attachment; filename="domain.mobileconfig"');
header('Content-Transfer-Encoding: binary');
ob_clean();
flush();
readfile("/var/www/html/apple/$timestamp.signed");
flush();

unlink("/var/www/html/apple/$timestamp");
unlink("/var/www/html/apple/$timestamp.signed");

?>
<?php else: ?>

<html>
<head>
<title>domain.com ActiveSync Configuration for Apple iOS</title>
<meta name="viewport" content="width=device-width; initial-scale=1; 
user-scalable=no" />
</head>
<body>
<form method="post" action="mailsetup.php">
<p style="text-align: center">
<b>Benutzer-Name:</b>
<br>&nbsp;<br>
<input type="text" name="name" style="height: 30px; width: 200px;"/>
<br>&nbsp;<br>
<input type="submit" value="Ok" style="width: 80px; height: 30px;"/>
</p>
</form>
</body>
</html>

<?php endif ?>

And the mailsetup.mobileconfig it references:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
        <dict>
                <key>PayloadUUID</key>
                <string>8B9C9E2E-53E7-44EC-A361-74EC8136B4CF</string>
                <key>PayloadDisplayName</key>
                <string>%EMAIL%</string>
                <key>PayloadIdentifier</key>
                <string>domain.profile</string>
                <key>PayloadDescription</key>
                <string>Configures the device for use with ActiveSync for 
domain.com</string>
                <key>PayloadOrganization</key>
                <string>DOMAIN</string>
                <key>PayloadVersion</key>
                <integer>1</integer>
                <key>PayloadType</key>
                <string>Configuration</string>
                <key>PayloadContent</key>
                <array>
                        <dict>
                                <key>PayloadUUID</key>
                                
<string>837AF5F3-1380-4234-BAD0-8246A644AC2E</string>
                                <key>PayloadDisplayName</key>
                                <string>%USERNAME%</string>
                                <key>PayloadDescription</key>
                                <string>Configures the device for use with 
ActiveSync for DOMAIN.</string>
                                <key>PayloadOrganization</key>
                                <string>DOMAIN</string>
                                <key>PayloadVersion</key>
                                <integer>1</integer>
                                <key>PayloadIdentifier</key>
                                <string>domain.email</string>
                                <key>PayloadType</key>
                                <string>com.apple.eas.account</string>
                                <key>UserName</key>
                                <string>%USERNAME%</string>
                                <key>EmailAddress</key>
                                <string>%EMAIL%</string>
                                <key>Host</key>
                                <string>webmail.domain.com</string>
                                <key>SSL</key>
                                <true/>
                        </dict>
                </array>
        </dict>
</plist>

Adapt for your needs … in the mailsetup.php it also references your server’s 
TLS certificate(s).

Kai-Uwe Rommel


From: users-requ...@sogo.nu <users-requ...@sogo.nu> On Behalf Of HYVERNAT 
Philippe
Sent: Thursday, January 6, 2022 8:39 PM
To: users@sogo.nu
Subject: [SOGo] Help to setup autoconfig and autodiscover


Hello community,

i don't know if it is the right feed but i want to configure autoconfig and 
autodiscover in the same web server of sogo.



I own Postfix / Dovecot Apache 24 and sogo 5.4



My web server is share with sogo and my setup is "webmail.domain.com"



I find scripts examples for both thunderbird and outlook but i don't know where 
to place them and how configure th web server apache to share files.



i use also redirection /sogo to /

Thanks by advance.

HYVERNAT PHILIPPE
--
users@sogo.nu
https://inverse.ca/sogo/lists

ARS Computer und Consulting GmbH, www.ars.de
ein Unternehmen der TIMETOACT Group
Garmischer Straße 7, 80339 München, Deutschland

ARS - The Art of Software Engineering
Software Engineering, Technologieberatung, IBM Software, IBM Lizenzmanagement 
Services

Handelsregister München, HRB 101829, USt-ID: DE 155 068 909
Geschäftsführer: Joachim Gucker, Stefan Schäffer, Michael Arbesmeier
Datenschutzerklärung: https://web.ars.de/datenschutz/
-- 
users@sogo.nu
https://inverse.ca/sogo/lists

Reply via email to