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