├── .gitignore
├── .htaccess
├── README.md
├── autodiscover.xml.php
├── mail
├── autodiscover.xml
└── config-v1.1.xml
└── settings.json.sample
/.gitignore:
--------------------------------------------------------------------------------
1 | settings.json
2 | *.swp
3 | .DS_Store
--------------------------------------------------------------------------------
/.htaccess:
--------------------------------------------------------------------------------
1 | Options -Indexes
2 | RewriteEngine On
3 | RewriteBase /
4 |
5 | RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
6 | RewriteRule ^(.*)$ - [E=BASE:%1]
7 |
8 | RewriteCond %{QUERY_STRING} ^(emailaddress)=(.*)$
9 | RewriteRule ^mail/(.*)$ %{ENV:BASE}autodiscover.xml.php?template=config-v1.1.xml&email=%2 [L]
10 |
11 | #RewriteCond %{REQUEST_FILENAME} -f
12 | RewriteRule ^mail/(.*)$ %{ENV:BASE}autodiscover.xml.php?template=config-v1.1.xml&email=$1 [L]
13 |
14 | #RewriteRule ^(.*)/?mail/(.*)$ info.php [L]
15 | RewriteRule ^(.*)/?autodiscover\.xml$ autodiscover.xml.php [L]
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | E-Mail Autoconfigure
2 | ====================
3 |
4 | Some E-Mail clients gather configuration information before setting up mail accounts. This project allows to provide clients like Outlook and Thunderbird the proper mail server configuration, so that users can simply enter their email and password to setup a new mail account.
5 |
6 | Installation
7 | ------------
8 |
9 | ### Apache Webserver
10 |
11 | You need an Apache webserver with PHP5 preconfigures. You can then configure your Virtual Host like this
12 |
13 | ```
14 |
15 | ServerName autodiscover.{{$DOMAIN}}
16 | ServerAlias autodiscover.{{$DOMAIN}} autoconfig.{{$DOMAIN}}
17 |
18 |
19 | Options -Indexes
20 | AllowOverride All
21 |
22 |
23 | ...
24 |
25 | ```
26 |
27 | Now copy `settings.json.sample` to your Virtual Host directory root and apply your configuration variables.
28 |
29 |
30 | ### Autoconfig for multiple domains on the same server
31 |
32 | When a user puts his E-Mail address `user@example.org` into his mail client, it will probably do a GET request on https://autodiscover.example.org/autodiscover/autodiscover.xml
33 |
34 | If you have multiple domains hosted on your mailserver, you can redirect those requests to your main-autoconfig server. Add this configuration to your existing Virtual Host configuration:
35 |
36 | ```
37 |
38 | ServerName example.org
39 | SSLEngine On
40 | ...
41 |
42 | RewriteEngine On
43 | RewriteCond %{HTTP_HOST} ^autodiscover\. [NC]
44 | RewriteRule ^/(.*) https://autodiscover.{{$DOMAIN}}/$1 [L,R=301,NE]
45 |
46 | RewriteCond %{HTTP_HOST} ^autoconfig\. [NC]
47 | RewriteRule ^/(.*) https://autoconfig.{{$DOMAIN}}/$1 [L,R=301,NE]
48 | ...
49 |
50 |
51 |
52 | ServerName example.org
53 |
54 | RewriteEngine On
55 | RewriteCond %{HTTP_HOST} ^autodiscover\. [NC]
56 | RewriteRule ^/(.*) https://autodiscover.{{$DOMAIN}}/$1 [L,R=301,NE]
57 |
58 | RewriteCond %{HTTP_HOST} ^autoconfig\. [NC]
59 | RewriteRule ^/(.*) https://autoconfig.{{$DOMAIN}}/$1 [L,R=301,NE]
60 | ...
61 |
62 |
63 | ```
64 |
65 |
66 | ### DNS Setup
67 |
68 | For the case you are using Bind and have the autoconfig HTTP server running on the same IP your `www.` subdomain resolves to, you can use this DNS records to configure your nameserver
69 |
70 | ```
71 | autoconfig IN CNAME www
72 | autodiscover IN CNAME www
73 |
74 | @ IN MX 10 {{$MX_DOMAIN}}.
75 | @ IN TXT "mailconf=https://autoconfig.{{$DOMAIN}}/mail/config-v1.1.xml"
76 | _imaps._tcp SRV 0 1 993 {{$MX_DOMAIN}}.
77 | _submission._tcp SRV 0 1 465 {{$MX_DOMAIN}}.
78 | _autodiscover._tcp SRV 0 0 443 autodiscover.{{$DOMAIN}}.
79 | ```
80 |
81 | Instead of a CNAME, you can of course also choose an A-record
82 |
83 | ```
84 | autoconfig IN A {{$AUTODISCOVER_IP}}
85 | autodiscover IN A {{$AUTODISCOVER_IP}}
86 | ```
87 |
88 | Replace above variables with data according to this table
89 |
90 | Variable | Description
91 | -----------------|-------------------------------------------------------------
92 | MX_DOMAIN | The hostname name of your MX server
93 | DOMAIN | Your apex/bare/naked Domain
94 | AUTODISCOVER_IP | IP of the Autoconfig HTTP
95 |
96 | ToDo
97 | ----
98 |
99 | * Allow other authentication methods (currently always required)
100 | * Support nginx HTTP server
101 | * Add client support table
102 | * Create a Makefile for easy installation
103 |
--------------------------------------------------------------------------------
/autodiscover.xml.php:
--------------------------------------------------------------------------------
1 | /sU';
42 | return preg_replace($pattern, '', $xml);
43 | }
44 |
45 | function beautify ($xml) {
46 | $dom = new DOMDocument;
47 | $dom->preserveWhiteSpace = false;
48 | $dom->loadXML($xml);
49 | $dom->formatOutput = true;
50 | return $dom->saveXml();
51 | }
52 |
53 | function isOnOrOff ($value) {
54 | return ($value === true) ? 'on' : 'off';
55 | }
56 |
57 | function loadConfig () {
58 | return json_decode(implode('', file('settings.json')), true);
59 | }
60 |
61 | function loadTemplate ($file) {
62 | return implode("",file($file));
63 | }
64 |
65 | function determineTemplateFile () {
66 |
67 | $template = array_key_exists('template', $_GET) ? $_GET['template'] : null;
68 |
69 | switch($template) {
70 |
71 | case "config-v1.1.xml":
72 | $file = 'mail/config-v1.1.xml';
73 | break;
74 |
75 | default:
76 | $file = 'mail/autodiscover.xml';
77 | break;
78 |
79 | }
80 |
81 | return $file;
82 |
83 | }
84 |
85 | function getRequestEmail () {
86 |
87 | $email = array_key_exists('email', $_GET) ? $_GET['email'] : null;
88 | return filter_var($email, FILTER_VALIDATE_EMAIL);
89 |
90 | }
91 |
92 | ?>
93 |
--------------------------------------------------------------------------------
/mail/autodiscover.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
10 |
11 |
14 | %INFO/NAME%
15 |
16 |
17 |
20 |
21 |
27 | email
28 |
29 |
36 | settings
37 |
38 |
43 |
44 |
49 |
50 |
55 |
56 |
59 | %INFO/URL%
60 |
61 |
64 |
65 |
74 | IMAP
75 |
76 |
81 |
82 |
85 | %TTL%
86 |
87 |
92 | %SERVER/IMAP/HOST%
93 |
94 |
97 | %SERVER/IMAP/PORT%
98 |
99 |
104 |
105 |
108 | %SERVER/IMAP/DOMAIN_REQUIRED%
109 |
110 |
115 |
116 |
120 | off
121 |
122 |
126 | %SERVER/IMAP/SSL_ON%
127 |
128 |
132 | on
133 |
134 |
138 | on
139 |
140 |
143 | off
144 |
145 |
146 |
147 | SMTP
148 | %TTL%
149 | %SERVER/SMTP/HOST%
150 | %SERVER/SMTP/PORT%
151 | %SERVER/SMTP/DOMAIN_REQUIRED%
152 | off
153 | %SERVER/SMTP/SSL_ON%
154 | on
155 | on
156 | off
157 |
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/mail/config-v1.1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %INFO/DOMAIN%
6 | %INFO/NAME%
7 | %INFO/NAME%
8 |
9 | %SERVER/IMAP/HOST%
10 | %SERVER/IMAP/PORT%
11 | %SERVER/IMAP/SOCKET%
12 | password-cleartext
13 | %EMAIL%
14 |
15 |
16 | %SERVER/SMTP/HOST%
17 | %SERVER/SMTP/PORT%
18 | %SERVER/SMTP/SOCKET%
19 | password-cleartext
20 | %EMAIL%
21 |
22 |
23 | Allgemeine Beschreibung der Einstellungen
24 | Generic settings page
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/settings.json.sample:
--------------------------------------------------------------------------------
1 | {
2 | "info": {
3 | "name": "{{$COMPANY_NAME}}",
4 | "url": "{{$SUPPORT_URL}}",
5 | "domain": "{{$DOMAIN}}"
6 | },
7 | "server": {
8 | "imap": {
9 | "host": "{{$IMAP_HOST}}",
10 | "port": {{$IMAP_PORT}},
11 | "socket": "SSL"
12 | },
13 | "smtp": {
14 | "host": "{{$SMTP_HOST}}",
15 | "port": {{$SMTP_PORT}},
16 | "socket": "SSL"
17 | },
18 | "domain_required": true
19 | },
20 | "ttl": 168
21 | }
--------------------------------------------------------------------------------