system-configuration/modules/config/mail.scm

mail.scm

1
;;; Tyreunom's system administration and configuration tools.
2
;;;
3
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
4
;;;
5
;;; This program is free software: you can redistribute it and/or modify
6
;;; it under the terms of the GNU General Public License as published by
7
;;; the Free Software Foundation, either version 3 of the License, or
8
;;; (at your option) any later version.
9
;;;
10
;;; This program is distributed in the hope that it will be useful,
11
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;; GNU General Public License for more details.
14
;;;
15
;;; You should have received a copy of the GNU General Public License
16
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
;;
19
;; Email configuration
20
;;
21
22
(define-module (config mail)
23
  #:use-module (data dns)
24
  #:use-module (gnu services)
25
  #:use-module (gnu services mail)
26
  #:use-module (guix gexp)
27
  #:use-module (services mail)
28
  #:export (lepiller-mail-services))
29
30
(define aliases-file
31
  (plain-file "aliases" "postmaster root
32
33
@ tyreunom
34
"))
35
36
(define relays-file
37
  (plain-file "other-relays"
38
    (string-append ene-ip4 "\n" hermes-ip4 "\n" hermes-ip6 "\n" )))
39
40
(define blacklist-file
41
  (plain-file "blacklist" "
42
@yahoo.com.cn
43
@qq.com"))
44
45
(define (opensmtpd-conf interface domain)
46
  (mixed-text-file "smtpd.conf" "
47
# This is the smtpd server system-wide configuration file.
48
# See smtpd.conf(5) for more information.
49
50
# My TLS certificate and key
51
pki lepiller.eu certificate \"/etc/letsencrypt/live/" domain "/fullchain.pem\"
52
pki lepiller.eu key \"/etc/letsencrypt/live/" domain "/privkey.pem\"
53
54
# Edit this file to add more virtual users (passwords are read in that file
55
# instead of /etc/passwd.
56
table passwd file:/etc/mail/passwd
57
58
# port 25 is used only for receiving from external servers, and they may start a
59
# TLS session if the want.
60
listen on " interface " port 25 tls pki lepiller.eu
61
# For sending messages from outside of this server, you need to authenticate and
62
# use TLS.
63
listen on " interface " port 587 tls-require pki lepiller.eu mask-source auth <passwd>
64
# On this server, you only need to authenticate on one of the available ports,
65
# and you may use TLS.
66
listen on lo port 25 tls pki lepiller.eu mask-source auth <passwd>
67
listen on lo port 587 tls pki lepiller.eu mask-source auth <passwd>
68
listen on lo port 10028 tag DKIM_OUT # DKIMproxy
69
70
# Maybe it'll work better if we connect to gmail only with v4?
71
limit mta for domain gmail.com inet4
72
73
# TODO: manage these files directly in the configuration?
74
# If you edit the file, you have to run \"smtpctl update table aliases\"
75
table aliases file:" aliases-file "
76
77
table other-relays file:" relays-file "
78
table blacklist file:" blacklist-file "
79
80
# We accept to relay any mail from authenticated users
81
accept for any authenticated relay via smtp://127.0.0.1:10027
82
accept tagged DKIM_OUT for any relay
83
84
# Then, we reject on some other conditions:
85
86
# If the mail tries to impersonate us
87
reject from ! source <other-relays> sender \"@lepiller.eu\" for any
88
# If it comes from someone on the blacklist
89
reject from any sender <blacklist> for any
90
91
# Finaly, if we accept incoming messages
92
accept from any for domain \"lepiller.eu\" virtual <aliases> deliver to maildir
93
accept for local alias <aliases> deliver to maildir
94
"))
95
96
(define (lepiller-imap-service domain)
97
  (service dovecot-service-type
98
           (dovecot-configuration
99
             (mail-location "maildir:~/Maildir")
100
             (ssl-cert (string-append
101
                         "</etc/letsencrypt/live/" domain "/fullchain.pem"))
102
             (ssl-key  (string-append
103
                         "</etc/letsencrypt/live/" domain "/privkey.pem")))))
104
105
(define (lepiller-smtp-service interface domain)
106
  (service opensmtpd-service-type
107
           (opensmtpd-configuration
108
             (config-file (opensmtpd-conf interface domain)))))
109
110
(define (lepiller-dkim-service domain)
111
  (service dkimproxy-out-service-type
112
           (dkimproxy-out-configuration
113
             (listen "127.0.0.1:10027")
114
             (relay "127.0.0.1:10028")
115
             (sender-map
116
               `((,domain
117
                  (,(dkimproxy-out-signature-configuration
118
                      (type 'dkim)
119
                      (key "/etc/mail/dkim/private.key")
120
                      (method "relaxed")
121
                      (selector "dkim"))
122
                   ,(dkimproxy-out-signature-configuration
123
                      (type 'domainkeys)
124
                      (method "nofws")))))))))
125
126
(define* (lepiller-mail-services #:key interface domain)
127
  (list
128
    (lepiller-smtp-service interface domain)
129
    (lepiller-imap-service domain)
130
    (lepiller-dkim-service domain)))
131
132