Browse Source

Generate mail autoconfig for all domains and put them in well-known too

Thomas Buck 5 years ago
parent
commit
f7094f17dd

+ 2
- 1
roles/mailserver/defaults/main.yml View File

10
 mail_db_password: "{{ lookup('password', secret + '/' + 'mail_db_password length=32') }}"
10
 mail_db_password: "{{ lookup('password', secret + '/' + 'mail_db_password length=32') }}"
11
 mail_db_database: 'mailserver'
11
 mail_db_database: 'mailserver'
12
 
12
 
13
-mail_server_hostname: "mail.{{ domain }}"
13
+mail_server_subdomain: "mail"
14
+mail_server_hostname: "{{ mail_server_subdomain }}.{{ domain }}"
14
 mail_server_autoconfig_hostname: "autoconfig.{{ domain }}"
15
 mail_server_autoconfig_hostname: "autoconfig.{{ domain }}"
15
 mail_header_privacy: 1
16
 mail_header_privacy: 1
16
 
17
 

+ 11
- 11
roles/mailserver/tasks/autoconfig.yml View File

2
 #
2
 #
3
 # Autoconfig XML file for email clients
3
 # Autoconfig XML file for email clients
4
 # https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration
4
 # https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration
5
-#
6
-
7
-- name: Create directory for mail autoconfiguration virtualhost
8
-  file:
9
-    state=directory
10
-    path=/var/www/autoconfig
11
-    owner=root
12
-    group=www-data
13
 
5
 
14
-- name: Create directory holding the autoconfig XML file
6
+- name: Create directories holding the autoconfig XML file
15
   file:
7
   file:
16
     state=directory
8
     state=directory
17
-    path=/var/www/autoconfig/mail
9
+    path={{ item }}
18
     owner=root
10
     owner=root
19
     group=www-data
11
     group=www-data
12
+  with_items:
13
+    - "/var/www/autoconfig"
14
+    - "/var/www/autoconfig/mail"
15
+    - "/var/www/well-known/autoconfig"
16
+    - "/var/www/well-known/autoconfig/mail"
20
 
17
 
21
 - name: Create the autoconfig XML file
18
 - name: Create the autoconfig XML file
22
   template:
19
   template:
23
     src=var_www_autoconfig_mail_config-v1.1.j2
20
     src=var_www_autoconfig_mail_config-v1.1.j2
24
-    dest=/var/www/autoconfig/mail/config-v1.1.xml
21
+    dest={{ item }}
25
     owner=root
22
     owner=root
26
     group=www-data
23
     group=www-data
24
+  with_items:
25
+    - "/var/www/autoconfig/mail/config-v1.1.xml"
26
+    - "/var/www/well-known/autoconfig/mail/config-v1.1.xml"
27
 
27
 
28
 - name: Configure the mail autoconfiguration virtualhost
28
 - name: Configure the mail autoconfiguration virtualhost
29
   template:
29
   template:

+ 9
- 7
roles/mailserver/templates/var_www_autoconfig_mail_config-v1.1.j2 View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <clientConfig version="1.1">
2
 <clientConfig version="1.1">
3
-    <emailProvider id="{{ domain }}">
4
-        <domain>{{ domain }}</domain>
5
-        <displayName>{{ domain }}</displayName>
6
-        <displayShortName>{{ domain }}</displayShortName>
3
+{% for vd in virtual_domains %}
4
+    <emailProvider id="{{ vd.name }}">
5
+        <domain>{{ vd.name }}</domain>
6
+        <displayName>{{ vd.name }}</displayName>
7
+        <displayShortName>{{ vd.name }}</displayShortName>
7
         <incomingServer type="imap">
8
         <incomingServer type="imap">
8
-            <hostname>{{ mail_server_hostname }}</hostname>
9
+            <hostname>{{ mail_server_subdomain }}.{{ vd.name }}</hostname>
9
             <port>993</port>
10
             <port>993</port>
10
             <socketType>SSL</socketType>
11
             <socketType>SSL</socketType>
11
             <authentication>password-cleartext</authentication>
12
             <authentication>password-cleartext</authentication>
12
             <username>%EMAILADDRESS%</username>
13
             <username>%EMAILADDRESS%</username>
13
         </incomingServer>
14
         </incomingServer>
14
         <incomingServer type="pop3">
15
         <incomingServer type="pop3">
15
-            <hostname>{{ mail_server_hostname }}</hostname>
16
+            <hostname>{{ mail_server_subdomain }}.{{ vd.name }}</hostname>
16
             <port>995</port>
17
             <port>995</port>
17
             <socketType>SSL</socketType>
18
             <socketType>SSL</socketType>
18
             <authentication>password-cleartext</authentication>
19
             <authentication>password-cleartext</authentication>
19
             <username>%EMAILADDRESS%</username>
20
             <username>%EMAILADDRESS%</username>
20
         </incomingServer>
21
         </incomingServer>
21
         <outgoingServer type="smtp">
22
         <outgoingServer type="smtp">
22
-            <hostname>{{ mail_server_hostname }}</hostname>
23
+            <hostname>{{ mail_server_subdomain }}.{{ vd.name }}</hostname>
23
             <port>587</port>
24
             <port>587</port>
24
             <socketType>STARTTLS</socketType>
25
             <socketType>STARTTLS</socketType>
25
             <authentication>password-cleartext</authentication>
26
             <authentication>password-cleartext</authentication>
26
             <username>%EMAILADDRESS%</username>
27
             <username>%EMAILADDRESS%</username>
27
         </outgoingServer>
28
         </outgoingServer>
28
     </emailProvider>
29
     </emailProvider>
30
+{% endfor %}
29
 </clientConfig>
31
 </clientConfig>

Loading…
Cancel
Save