AutoConfigure

This section contains user-submitted tutorials.
User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

AutoConfigure

Postby mattg » 2017-08-09 02:24

Autoconfigure is where you have some files on your webserver, and/or some DNS records, that specify your mail server settings for new account creation.
Thunderbird supports Autoconfigure, as does Outlook, but they use different methods.

I require StartTLS on port 110 - POP3, 143 - IMAP and 587 - SMTP submission, with IMAP having priority over POP3. (IMAP is first in my examples)

Thunderbird
you need the following file accessible at 'http://www.example.com/.well-known/autoconfigure/mail/config-v1.1.xml'

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<clientConfig version="1.1">
  <emailProvider id="example.com">
    <domain>example.com</domain>
    <displayName>eMail by example.com</displayName>
    <displayShortName>EXAMPLE</displayShortName>
    <incomingServer type="imap">
      <hostname>mail.example.com</hostname>
      <port>143</port>
      <socketType>STARTTLS</socketType>
      <authentication>password-cleartext</authentication>
      <username>%EMAILADDRESS%</username>
    </incomingServer>
    <incomingServer type="pop3">
      <hostname>mail.example.com</hostname>
      <port>110</port>
      <socketType>STARTTLS</socketType>
      <authentication>password-cleartext</authentication>
      <username>%EMAILADDRESS%</username>
    </incomingServer>
    <outgoingServer type="smtp">
      <hostname>mail.example.com</hostname>
      <port>587</port>
      <socketType>STARTTLS</socketType>
      <authentication>password-cleartext</authentication>
      <username>%EMAILADDRESS%</username>
    </outgoingServer>
  </emailProvider>
</clientConfig>


Outlook
(I've used PHP, but you can also use ASP, or Perl or ... to get the input values. PHP was easy for me)
you need the following file accessible at 'http://www.example.com/autodiscover/autodiscover.php'

Code: Select all

<?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" ?>'; ?>

<!-- info used from the following sites
http://www.virer.net/info/ol-autodiscover/index.html
https://technet.microsoft.com/en-us/library/cc511507.aspx
-->
<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.example.com</Server>
            <Port>143</Port>
            <DomainRequired>on</DomainRequired>
                               <LoginName><?php echo $matches[1]; ?></LoginName>
            <SPA>off</SPA>
            <Encryption>TLS</Encryption>
            <AuthRequired>on</AuthRequired>
         </Protocol>
         <Protocol>
            <Type>POP3</Type>
            <Server>mail.example.com</Server>
            <Port>110</Port>
            <DomainRequired>on</DomainRequired>
               <LoginName><?php echo $matches[1]; ?></LoginName>
            <SPA>off</SPA>
            <Encryption>TLS</Encryption>
            <AuthRequired>on</AuthRequired>
         </Protocol>
         <Protocol>
            <Type>SMTP</Type>
            <Server>mail.example.com</Server>
            <Port>587</Port>
            <DomainRequired>on</DomainRequired>
               <LoginName><?php echo $matches[1]; ?></LoginName>
            <SPA>off</SPA>
            <Encryption>TLS</Encryption>
            <AuthRequired>on</AuthRequired>
         </Protocol>
      </Account>
   </Response>
</Autodiscover>


A rewrite of the URL is also needed.
I use Apache and so rewrite is done with .htaccess (IIS needs a rewrite module added, and rules are generated and tested using the IIS Admin GUI, or a web.config file should be generated)

Code: Select all

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ autodiscover.php [NC,L]
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
RvdH
Senior user
Senior user
Posts: 455
Joined: 2008-06-27 14:42
Location: Netherlands

Re: AutoConfigure

Postby RvdH » 2017-08-09 11:31

automatically configure Outlook/Thunderbird via asp.net
https://vdhout.nl/2015/04/hmailserver-a ... figuration
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-10 01:12

And yes I used your guide extensively thanks when I did this on IIS. (and couldn't find the link when I went looking - thanks for posting again)
I just recently moved to an Apache2 Server for my website hosting (MUCH faster) of a few Wordpress sites and some other bits and pieces and had to do autoconfigure again.


My current plan is adding a CalDAV / CardDAV server to my Ubuntu Webserver, with autoconfigure for the address book and calendar - still working on that.
I have created DNS records, but not sure yet that they all work as I expect. I am trying hard to stick with hMailserver and not move to a Linux Groupware solution, although in reality hMailserver is about all that is on that Windows VM at the moment. that and a couple of older website that I haven't migrated to PHP7.0 yet.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
Dravion
Senior user
Senior user
Posts: 692
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: AutoConfigure

Postby Dravion » 2017-08-10 06:12

I did this Thunderbird Autoconfig and MS-Outlook Autodiscover thing a while ago and i noticed the following:

1)
Allways take a good look at your Webserver logfiles, this really helps a lot at debugging.

2)
Outlook Autodiscover needs a proper configured
SSL-Website with a valid SSL-Certificate by a trusted CA or you get nasty Warning Popups in Outlook.
My experimental builds of hMailserver 32/64-Bit+Unicode
https://github.com/Dravion/hmailserver/releases

HMSInfo 32/64-Bit
https://github.com/Dravion/HMSInfo/releases

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-10 06:25

Dravion wrote:2)
Outlook Autodiscover needs a proper configured
SSL-Website with a valid SSL-Certificate by a trusted CA or you get nasty Warning Popups in Outlook.

Lets Encrypt wins again

I'm loving that since it was pointed out to me, and on Linux is SOOO easy
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 2308
Joined: 2006-08-21 15:38
Location: Denmark

Re: AutoConfigure

Postby SorenR » 2017-08-10 17:55

mattg wrote:A rewrite of the URL is also needed.
I use Apache and so rewrite is done with .htaccess (IIS needs a rewrite module added, and rules are generated and tested using the IIS Admin GUI, or a web.config file should be generated)

Code: Select all

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 you come up with a solution on having mod_speling and mod_rewrite in the same .htaccess file give me a buzz... This casesensitiveness with unix is mostly crap coming from Windows :mrgreen:

Not sure what the -s and -l is good for... I use this...

Code: Select all

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{HTTPS} !=on
   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   RewriteCond %{HTTP_HOST} !^www\. [NC]
   RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   RewriteBase /
   RewriteRule ^index\.php$ - [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /index.php [L]
</IfModule>

# log PHP errors to a file
   php_flag log_errors on
   php_value error_reporting 32767
   php_value error_log /volume1/web/bbblog/PHP_errors.log
SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

Freescape
New user
New user
Posts: 4
Joined: 2017-06-25 22:30

Re: AutoConfigure

Postby Freescape » 2017-08-10 22:41

Just to add, the latest Outlook 2016 update in July has broken this autodiscover route btw.

Interestingly, if you do the ctrl-right-click on the systray outlook icon and run the "Test email Autoconfiguration" tool, it will say your autodiscovery is fine, but try to actually set up an email account and it won't work.

Unclear if this is intended or just a bug. (Like releasing all the office binaries signed with an untrusted test cert in the same update)

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-11 01:08

SorenR wrote:Not sure what the -s and -l is good for...

TBH me neither, I copied that from http://www.virer.net/info/ol-autodiscover/index.html as detailed in my code
It worked for me, that's what counts for me.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html and search for '-l' including the quotes and they are defined there.
What is their use? No idea

Freescape wrote:Just to add, the latest Outlook 2016 update in July has broken this autodiscover route btw.

Nothing surprises me with MS and Outlook any more. It really is like they try to make it worse each iteration.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 2308
Joined: 2006-08-21 15:38
Location: Denmark

Re: AutoConfigure

Postby SorenR » 2017-08-11 14:01

mattg wrote:
SorenR wrote:Not sure what the -s and -l is good for...

TBH me neither, I copied that from http://www.virer.net/info/ol-autodiscover/index.html as detailed in my code
It worked for me, that's what counts for me.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html and search for '-l' including the quotes and they are defined there.
What is their use? No idea

Freescape wrote:Just to add, the latest Outlook 2016 update in July has broken this autodiscover route btw.

Nothing surprises me with MS and Outlook any more. It really is like they try to make it worse each iteration.

Code: Select all

<IfModule mod_rewrite.c>
   RewriteEngine On

   # (-s) does target exist and is it a regular file
   # (-l) does target exist and is it a symlink
   # (-d) does target exist and is it a directory

   RewriteCond %{REQUEST_FILENAME} -s [OR]
   RewriteCond %{REQUEST_FILENAME} -l [OR]
   RewriteCond %{REQUEST_FILENAME} -d

   # (NC) match is case insensitive
   # (L)  last directive, if matched no further rules are executed

   RewriteRule ^.*$ - [NC,L]
   RewriteRule ^.*$ autodiscover.php [NC,L]

</IfModule>


So... It's crap... -s, -l, -d verifies that %{REQUEST_FILENAME} is either A File, A Symbolic link to a File OR A Directory... No other choices in Unix really.

And the two rewrite rules... L means stop processing rules and if the first line matches, the second line is never processed and if the first line do not match, the second line won't either as the match is identical.

And ... This "RewriteRule ^.*$ -" is like a "NOP" statement in programming.

Am I wrong here ??
SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

User avatar
SorenR
Senior user
Senior user
Posts: 2308
Joined: 2006-08-21 15:38
Location: Denmark

Re: AutoConfigure

Postby SorenR » 2017-08-11 16:15

Hmm... Found a htaccess test site that I just had to try.

http://htaccess.mwl.be/

NB: domain changed.

Actual URL: Verified, when loaded in a browser it WILL show the XML output.

Code: Select all

https://www.acme.inc/.well-known/autodiscover/autodiscover.php


htaccess to be tested:

Code: Select all

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


Output URL (result):

Code: Select all

https://www.acme.inc/autodiscover.php


Debugging info:

Code: Select all

1   RewriteCond %{REQUEST_FILENAME} -s [OR]   This condition was not met but the [OR] option made it pass.
2   RewriteCond %{REQUEST_FILENAME} -l [OR]   This condition was not met but the [OR] option made it pass.
3   RewriteCond %{REQUEST_FILENAME} -d   This condition is not met.
4   RewriteRule ^.*$ - [NC,L]   This rule was not met.
5   RewriteRule ^.*$ autodiscover.php [NC,L]   The new url is https://www.lolle.org/autodiscover.php
The tests are stopped because of the L in your RewriteRule options.
SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-11 16:42

I knew It worked, but I wasn't sure about how
Thanks for the confirmation
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 2308
Joined: 2006-08-21 15:38
Location: Denmark

Re: AutoConfigure

Postby SorenR » 2017-08-11 17:10

mattg wrote:I knew It worked, but I wasn't sure about how
Thanks for the confirmation

That is not exactly my conclusion... Anyways %{REQUEST_FILENAME} means the actual filesystem path and file so this can't be tested from outside... So... my test is crap :mrgreen:
SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

AndreL
Normal user
Normal user
Posts: 30
Joined: 2016-06-07 15:42

Re: AutoConfigure

Postby AndreL » 2017-08-11 17:25

For Outlook I use this simple autodiscover.xml file (without any rewrite):
(in https://example.com/autodiscover)

Code: Select all

<?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>imap.example.com</Server>
            <Port>993</Port>
            <DomainRequired>on</DomainRequired>
            <DomainName>example.com</DomainName>
            <SPA>off</SPA>
            <SSL>on</SSL>
            <AuthRequired>on</AuthRequired>
         </Protocol>
         <Protocol>
            <Type>SMTP</Type>
            <Server>smtp.example.com</Server>
            <Port>465</Port>
            <DomainRequired>on</DomainRequired>
            <DomainName>example.com</DomainName>
            <SPA>off</SPA>
            <SSL>on</SSL>
            <AuthRequired>on</AuthRequired>
            <UsePOPAuth>off</UsePOPAuth>
         </Protocol>
      </Account>
   </Response>
</Autodiscover>

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-11 17:29

Thanks
That's much better

(Didn't realise that you could use DomainName)

What ideas do we have for CalDav and CardDAV autoconfigue?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-12 01:05

That doesn't make username in the form 'user@example.com.au', but leaves username in the form 'user'

That's why I was using re-write rules, to get the value of user and then use that to construct the correct login credentials
If that works for you without re-write rules, my guess is that you have a default domain set in hMailserver...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Freescape
New user
New user
Posts: 4
Joined: 2017-06-25 22:30

Re: AutoConfigure

Postby Freescape » 2017-08-14 01:01

mattg wrote:What ideas do we have for CalDav and CardDAV autoconfigue?


The only thing I've implemented that actually works is z-push with activesync autodiscovery. Basically you end up pretending to be an exchange activesync server with IMAP back-end store on HMS or anything. I was using nextcloud for the caldav/carddav backend.

This all works nicely for clients EXCEPT outlook. :-)

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-14 02:21

Z-push looks interesting thanks...

I'm already all over Nextcloud. Loving that too.
Currently I have a separate Ubuntu VM just for Nextcloud, but I am thinking of migrating that to my main Ubuntu Apache2 webserver.

Current live VMs on my HyperV server 2012R2 box
#1 Windows 10 pro - runs hMailserver , and a couple of older PHP5.4 IIS websites that haven't yet ported to PHP7, and PHPWebAdmin for hMailserver
#2 Firewall / router specific VM
#3 My SpamAppliance which is Ubuntu + SpamAssassin + ClamAV + SaneSecurity + Bind9
#4 My Ubuntu Apache2 Webserver serving PHP7 and reverse proxying to the other internet facing machines on port 80 (IIS and Nextcloud)
#5 Ubuntu + Nextcloud

All this on 16 GB RAM and single quad core processor, 5 year old Dell Entry level Server (of which the Windows 10 VM uses half), and a number of RAID1 drive sets.
I was given the server (when it got replaced) and all I've purchased is a Windows 10 Pro licence, and some hard drives / drive caddies.

Just got given another old server, I'm thinking of setting up real time replication / failover, at least for some of the VMs.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-28 04:21

I've noticed that Windows 10 Mail doesn't adhere to autoconfigure like Outlook does.

Any suggestions for dealing with Windows 10 Mail?? Google doesn't turn up much for me...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 2308
Joined: 2006-08-21 15:38
Location: Denmark

Re: AutoConfigure

Postby SorenR » 2017-08-28 17:34

mattg wrote:I've noticed that Windows 10 Mail doesn't adhere to autoconfigure like Outlook does.

Any suggestions for dealing with Windows 10 Mail?? Google doesn't turn up much for me...

I have both the "Mozilla" solution and the "Outlook" solution (by AndreL) on my webserver (no .htaccess btw) and for Windows10, all I have to do is select; "Other" -> email address, name and password...
Works for eM Client also (Outlook alternative). There is a free "Non-Profit" 2-account license. :wink:

I have not checked which one of the XML's work ... but it appears to do the job. Hey - 100% success - Who cares :mrgreen:

https:\\my.web.site\.well-known\autoconfigure\mail\config-v1.1.xml

and

https:\\my.web.site\autodiscover\autodiscover.xml

Both files laid out as described otherwise in this thread.
SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

User avatar
mattg
Moderator
Moderator
Posts: 17398
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: AutoConfigure

Postby mattg » 2017-08-29 02:46

Yep those two things work for me for All versions of Outlook that I have tried, and also Thunderbird. It works for my iPhone mail client.

It doesn't work for the Windows 10 Mail app that ships with Windows 10. I select 'Other' and still have to manually enter all details
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation


Return to “User-submitted tutorials”



Who is online

Users browsing this forum: No registered users and 1 guest