make unbound dependency for postfix optional
[ansible.git] / roles / email / templates / main.cf
1 compatibility_level = 2
2
3 # local delivery: aliases only
4 alias_maps = hash:/etc/aliases
5 local_recipient_maps = $alias_maps
6 {% if postfix.mynetworks is defined %}
7 mynetworks = {{ postfix.mynetworks }}
8 {% endif %}
9
10 {% if 'letsencrypt' in group_names %}
11 # TLS server parameters
12 smtpd_tls_cert_file=/etc/ssl/mycerts/letsencrypt/live.crt+chain
13 smtpd_tls_key_file=/etc/ssl/private/letsencrypt/live.key
14 smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
15 smtpd_tls_security_level = may
16 smtpd_tls_loglevel = 1
17 smtpd_tls_dh1024_param_file = /etc/ssl/dh2048.pem
18 smtpd_tls_mandatory_protocols = !SSLv2 !SSLv3
19 smtpd_tls_ciphers = low
20 smtpd_tls_mandatory_ciphers = high
21 {% endif %}
22 # TLS client parameters
23 smtp_tls_mandatory_protocols = !SSLv2 !SSLv3
24 smtp_tls_ciphers = low
25 smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
26 smtp_tls_loglevel = 1
27 {% if 'unbound' in group_names %}
28 # If there are TLSA records, enforce using encryption
29 smtp_dns_support_level = dnssec
30 smtp_tls_security_level = dane
31 {% endif %}
32
33 {% if postfix.postscreen | default(False) %}
34 # postscreen config
35 postscreen_dnsbl_threshold = 3
36 postscreen_dnsbl_whitelist_threshold = -2
37 postscreen_dnsbl_sites =
38         ix.dnsbl.manitu.net*2 sbl-xbl.spamhaus.org*2
39         bl.spamcop.net dnsbl.sorbs.net bl.mailspike.net
40         swl.spamhaus.org*-2 list.dnswl.org=127.0.[0..255].[0..254]*-2
41 postscreen_greet_action = enforce
42 postscreen_dnsbl_action = enforce
43 postscreen_pipelining_enable = yes
44 postscreen_non_smtp_command_enable = yes
45 postscreen_bare_newline_enable = yes
46 {% endif %}
47
48 # control relay access
49 smtpd_relay_restrictions = permit_mynetworks, permit_tls_clientcerts,
50     # allow nobody else
51     defer_unauth_destination
52 # spam-protection restrictions
53 smtpd_helo_required = yes
54 smtpd_recipient_restrictions = permit_mynetworks, permit_tls_clientcerts,
55     # check everybody else
56     reject_unauth_pipelining,
57     reject_invalid_helo_hostname,
58     reject_non_fqdn_recipient,
59     reject_non_fqdn_sender,
60
61 {% if postfix.relay_host is defined %}
62 # Relay everything
63 default_transport = smtp:{{ postfix.relay_host }}
64 {% if postfix.relay_client_cert is defined %}
65 # Enforce relay encryption
66 smtp_tls_cert_file=$config_directory/{{ postfix.relay_client_cert }}.crt
67 smtp_tls_key_file=$config_directory/{{ postfix.relay_client_cert }}.key
68 smtp_tls_security_level = encrypt
69 {% endif %}
70 {% endif %}
71
72 {% if postfix.submission | default(False) %}
73 # configure SASL
74 smtpd_sasl_type = dovecot
75 smtpd_sasl_path = private/auth
76 {% endif %}
77
78 {% if postfix.relay_client_cert_whitelist is defined %}
79 # allow relay for some TLS-authenticated clients
80 smtpd_tls_ask_ccert = yes
81 smtpd_tls_fingerprint_digest = sha1
82 relay_clientcerts = hash:$config_directory/relay_clientcerts
83 {% endif %}
84
85 # setup virtual delivery domains, aliases and destinations
86 virtual_mailbox_domains =
87 {% if postfix.mailman is defined %}  {% for item in postfix.mailman.domains %} {{item}}{% endfor %}{% endif %}
88 {% if postfix.dovecot is defined %}  {% for item in postfix.dovecot.domains %} {{item}}{% endfor %}{% endif %}
89
90 virtual_alias_maps = hash:$config_directory/virtual_alias_map
91   {% if postfix.dovecot is defined %}
92   proxy:mysql:$config_directory/mysql_vmail_aliases.cf
93   {% endif %}
94
95 virtual_mailbox_maps =
96   {% if postfix.dovecot is defined %}
97   proxy:mysql:$config_directory/mysql_vmail_users.cf
98   {% endif %}
99   {% if postfix.mailman | default(False) %}
100   hash:/var/lib/mailman/data/virtual-mailman
101   {% endif %}
102
103 smtpd_sender_login_maps =
104   {% if postfix.dovecot is defined %}
105   proxy:mysql:$config_directory/mysql_vmail_users.cf
106   proxy:mysql:$config_directory/mysql_vmail_senders.cf
107   proxy:mysql:$config_directory/mysql_vmail_aliases.cf
108   {% endif %}
109
110 proxy_read_maps = $virtual_alias_maps $virtual_mailbox_maps $smtpd_sender_login_maps
111
112 # setup mail routes for virtual mail: all mail ends up being forwarded somewhere
113 virtual_transport = error
114 transport_maps = hash:$config_directory/transport_map
115 {% if postfix.mailman | default(False) %}
116 mailman_destination_recipient_limit = 1
117 {% endif %}
118
119 {% if postfix.smtp_outgoing is defined %}
120 # send mail via specific IP
121 default_transport = {{ postfix.default_smtp_outgoing }}
122 sender_dependent_default_transport_maps = hash:$config_directory/sender_transport_map
123 {% endif %}
124
125 {% if postfix.opendkim is defined %}
126 # DKIM & Milter
127 milter_default_action = accept
128 # Path must match opendkim.env
129 smtpd_milters = unix:opendkim/sock
130 non_smtpd_milters = $smtpd_milters
131 {% endif %}
132
133 # misc
134 smtpd_delay_reject = yes
135 disable_vrfy_command = yes
136 recipient_delimiter = +
137 delay_warning_time = 4h
138 message_size_limit = 21384000