]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add mail autoconfiguration
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 13 Oct 2023 11:57:09 +0000 (13:57 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 26 Oct 2023 22:13:33 +0000 (00:13 +0200)
systems/eldiron/dns.nix
systems/eldiron/websites/default.nix
systems/eldiron/websites/mail/mta-sts.nix

index b076f6264929c3e6eef69cd53109f346923a316c..3d5aafa4401707fcff2b93ac5cf81fbf1e5df8a2 100644 (file)
@@ -93,6 +93,11 @@ in
             # DMARC
             # p needs to be the first tag
             _dmarc.TXT = [ (toKV { _00__v = "DMARC1"; _01__p = if quarantine then "quarantine" else "none"; adkim = "s"; aspf = "s"; fo = "1"; rua = "mailto:postmaster+rua@immae.eu"; ruf = "mailto:postmaster+ruf@immae.eu"; }) ];
+
+            # Autoconfiguration for Outlook
+            autodiscover = ips servers.eldiron.ips.main;
+            # Autoconfiguration for Mozilla
+            autoconfig = ips servers.eldiron.ips.main;
           };
 
           # SPF
index 68205deebf4ce5b15d6f0e0681fb0708f38b6172..feecc31171ebf6fc2610744a9a1eeebf83e01bdc 100644 (file)
@@ -78,6 +78,75 @@ let
         </Directory>
       '';
     };
+    mail-autoconfig = {
+      extraConfig = let
+        autoconfig = pkgs.writeTextDir "config-v1.1.xml" ''
+          <?xml version="1.0"?>
+          <clientConfig version="1.1">
+            <emailProvider id="mail.immae.eu">
+              <domain>mail.immae.eu</domain>
+              <domain>%EMAILDOMAIN%</domain>
+              <displayName>Immae E-mail</displayName>
+              <displayShortName>Immae E-mail</displayShortName>
+
+              <incomingServer type="imap">
+                <hostname>imap.immae.eu</hostname>
+                <port>143</port>
+                <socketType>STARTTLS</socketType>
+                <username>%EMAILADDRESS%</username>
+                <authentication>password-cleartext</authentication>
+              </incomingServer>
+
+              <incomingServer type="imap">
+                <hostname>imap.immae.eu</hostname>
+                <port>993</port>
+                <socketType>SSL</socketType>
+                <username>%EMAILADDRESS%</username>
+                <authentication>password-cleartext</authentication>
+              </incomingServer>
+
+              <incomingServer type="pop3">
+                <hostname>pop.immae.eu</hostname>
+                <port>110</port>
+                <socketType>STARTTLS</socketType>
+                <username>%EMAILADDRESS%</username>
+                <authentication>password-cleartext</authentication>
+              </incomingServer>
+
+              <incomingServer type="pop3">
+                <hostname>pop.immae.eu</hostname>
+                <port>995</port>
+                <socketType>SSL</socketType>
+                <username>%EMAILADDRESS%</username>
+                <authentication>password-cleartext</authentication>
+              </incomingServer>
+
+              <outgoingServer type="smtp">
+                <hostname>smtp.immae.eu</hostname>
+                <port>587</port>
+                <socketType>STARTTLS</socketType>
+                <username>%EMAILADDRESS%</username>
+                <authentication>password-cleartext</authentication>
+              </outgoingServer>
+
+              <outgoingServer type="smtp">
+                <hostname>smtp.immae.eu</hostname>
+                <port>465</port>
+                <socketType>SSL</socketType>
+                <username>%EMAILADDRESS%</username>
+                <authentication>password-cleartext</authentication>
+              </outgoingServer>
+            </emailProvider>
+          </clientConfig>
+        '';
+      in ''
+        Alias /.well-known/autoconfig/mail "${autoconfig}"
+        <Directory ${autoconfig}>
+          AllowOverride None
+          Require all granted
+        </Directory>
+      '';
+    };
     apaxy = {
       extraConfig = (mypackages-lib.apache-theme { inherit theme_root; }).apacheConfig;
     };
index 24387027a1e64ca8b8522f0c6e6865e1a5352bd2..240bcdb96af5082bf49a77a1fbc5212ade9e8015 100644 (file)
@@ -17,11 +17,160 @@ let
       "cp ${file d} $out/${d.fqdn}.txt"
     ) domains)}
     '';
+  autoconfigRoot =
+    let autoconfig = pkgs.writeText "config-v1.1.xml" ''
+      <?xml version="1.0"?>
+      <clientConfig version="1.1">
+        <emailProvider id="mail.immae.eu">
+          <domain>mail.immae.eu</domain>
+          <domain>%EMAILDOMAIN%</domain>
+          <displayName>Immae E-mail</displayName>
+          <displayShortName>Immae E-mail</displayShortName>
+
+          <incomingServer type="imap">
+            <hostname>imap.immae.eu</hostname>
+            <port>143</port>
+            <socketType>STARTTLS</socketType>
+            <username>%EMAILADDRESS%</username>
+            <authentication>password-cleartext</authentication>
+          </incomingServer>
+
+          <incomingServer type="imap">
+            <hostname>imap.immae.eu</hostname>
+            <port>993</port>
+            <socketType>SSL</socketType>
+            <username>%EMAILADDRESS%</username>
+            <authentication>password-cleartext</authentication>
+          </incomingServer>
+
+          <incomingServer type="pop3">
+            <hostname>pop.immae.eu</hostname>
+            <port>110</port>
+            <socketType>STARTTLS</socketType>
+            <username>%EMAILADDRESS%</username>
+            <authentication>password-cleartext</authentication>
+          </incomingServer>
+
+          <incomingServer type="pop3">
+            <hostname>pop.immae.eu</hostname>
+            <port>995</port>
+            <socketType>SSL</socketType>
+            <username>%EMAILADDRESS%</username>
+            <authentication>password-cleartext</authentication>
+          </incomingServer>
+
+          <outgoingServer type="smtp">
+            <hostname>smtp.immae.eu</hostname>
+            <port>587</port>
+            <socketType>STARTTLS</socketType>
+            <username>%EMAILADDRESS%</username>
+            <authentication>password-cleartext</authentication>
+          </outgoingServer>
+
+          <outgoingServer type="smtp">
+            <hostname>smtp.immae.eu</hostname>
+            <port>465</port>
+            <socketType>SSL</socketType>
+            <username>%EMAILADDRESS%</username>
+            <authentication>password-cleartext</authentication>
+          </outgoingServer>
+        </emailProvider>
+      </clientConfig>
+    '';
+    autodiscover = pkgs.writeText "Autodiscover.xml" ''
+      <?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">
+          <User>
+            <DisplayName>Name</DisplayName>
+          </User>
+          <Account>
+            <AccountType>email</AccountType>
+            <Action>settings</Action>
+            <Protocol>
+              <Type>IMAP</Type>
+              <TTL>1</TTL>
+              <Server>imap.immae.eu</Server>
+              <Port>143</Port>
+              <DomainRequired>on</DomainRequired>
+              <SPA>off</SPA>
+              <SSL>off</SSL>
+              <AuthRequired>on</AuthRequired>
+            </Protocol>
+            <Protocol>
+              <Type>POP3</Type>
+              <TTL>1</TTL>
+              <Server>pop3.immae.eu</Server>
+              <Port>110</Port>
+              <DomainRequired>on</DomainRequired>
+              <SPA>off</SPA>
+              <SSL>off</SSL>
+              <AuthRequired>on</AuthRequired>
+            </Protocol>
+            <Protocol>
+              <Type>SMTP</Type>
+              <TTL>1</TTL>
+              <Server>smtp.immae.eu</Server>
+              <Port>587</Port>
+              <DomainRequired>on</DomainRequired>
+              <SPA>off</SPA>
+              <SSL>off</SSL>
+              <AuthRequired>on</AuthRequired>
+            </Protocol>
+            <Protocol>
+              <Type>IMAP</Type>
+              <TTL>1</TTL>
+              <Server>imap.immae.eu</Server>
+              <Port>993</Port>
+              <DomainRequired>on</DomainRequired>
+              <SPA>off</SPA>
+              <SSL>on</SSL>
+              <AuthRequired>on</AuthRequired>
+            </Protocol>
+            <Protocol>
+              <Type>POP3</Type>
+              <TTL>1</TTL>
+              <Server>pop3.immae.eu</Server>
+              <Port>995</Port>
+              <DomainRequired>on</DomainRequired>
+              <SPA>off</SPA>
+              <SSL>on</SSL>
+              <AuthRequired>on</AuthRequired>
+            </Protocol>
+            <Protocol>
+              <Type>SMTP</Type>
+              <TTL>1</TTL>
+              <Server>smtp.immae.eu</Server>
+              <Port>465</Port>
+              <DomainRequired>on</DomainRequired>
+              <SPA>off</SPA>
+              <SSL>on</SSL>
+              <AuthRequired>on</AuthRequired>
+            </Protocol>
+          </Account>
+        </Response>
+      </Autodiscover>
+    '';
+  in
+    pkgs.runCommand "autoconfig" {} ''
+      mkdir -p $out/mail
+      ln -s ${autoconfig} $out/mail/config-v1.1.xml
+      mkdir -p $out/AutoDiscover
+      ln -s ${autodiscover} $out/AutoDiscover/AutoDiscover.xml
+      mkdir -p $out/Autodiscover
+      ln -s ${autodiscover} $out/Autodiscover/Autodiscover.xml
+      mkdir -p $out/autodiscover
+      ln -s ${autodiscover} $out/autodiscover/autodiscover.xml
+    '';
   cfg = config.myServices.websites.tools.email;
 in
 {
   config = lib.mkIf cfg.enable {
-    security.acme.certs.mail.extraDomainNames = ["mta-sts.mail.immae.eu"] ++ map (v: "mta-sts.${v.fqdn}") domains;
+    security.acme.certs.mail.extraDomainNames =
+      [ "mta-sts.mail.immae.eu" "autoconfig.mail.immae.eu" "autodiscover.mail.immae.eu" ]
+      ++ map (v: "mta-sts.${v.fqdn}") domains
+      ++ map (v: "autoconfig.${v.fqdn}") domains
+      ++ map (v: "autodiscover.${v.fqdn}") domains;
     services.websites.env.tools.vhostConfs.mta_sts = {
       certName   = "mail";
       hosts = ["mta-sts.mail.immae.eu"] ++ map (v: "mta-sts.${v.fqdn}") domains;
@@ -38,5 +187,20 @@ in
         ''
       ];
     };
+    services.websites.env.tools.vhostConfs.mail_autoconfig = {
+      certName = "mail";
+      hosts = ["autoconfig.mail.immae.eu" "autodiscover.mail.immae.eu" ]
+        ++ map (v: "autoconfig.${v.fqdn}") domains
+        ++ map (v: "autodiscover.${v.fqdn}") domains;
+      root = autoconfigRoot;
+      extraConfig = [
+        ''
+          <Directory ${autoconfigRoot}>
+            Require all granted
+            Options -Indexes
+          </Directory>
+        ''
+      ];
+    };
   };
 }