exim4.conf.template 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. ######################################################################
  2. # #
  3. # Exim configuration file for Hestia Control Panel #
  4. # #
  5. ######################################################################
  6. #SPAMASSASSIN = yes
  7. #SPAM_SCORE = 50
  8. #SPAM_REJECT_SCORE = 100
  9. #CLAMD = yes
  10. smtp_banner = $smtp_active_hostname
  11. smtp_active_hostname = ${lookup dnsdb{>: defer_never,ptr=$interface_address}{${listextract{1}{$value}}}{$primary_hostname}}
  12. add_environment = <; PATH=/bin:/usr/bin
  13. keep_environment =
  14. disable_ipv6 = true
  15. smtputf8_advertise_hosts =
  16. domainlist local_domains = dsearch;/etc/exim4/domains/
  17. domainlist relay_to_domains = dsearch;/etc/exim4/domains/
  18. hostlist relay_from_hosts = 127.0.0.1
  19. hostlist whitelist = net-iplsearch;/etc/exim4/white-blocks.conf
  20. hostlist spammers = net-iplsearch;/etc/exim4/spam-blocks.conf
  21. no_local_from_check
  22. untrusted_set_sender = *
  23. acl_smtp_connect = acl_check_spammers
  24. acl_smtp_mail = acl_check_mail
  25. acl_smtp_rcpt = acl_check_rcpt
  26. acl_smtp_data = acl_check_data
  27. acl_smtp_mime = acl_check_mime
  28. .ifdef SPAMASSASSIN
  29. spamd_address = 127.0.0.1 783
  30. .endif
  31. .ifdef CLAMD
  32. av_scanner = clamd: /run/clamav/clamd.ctl
  33. .endif
  34. log_selector = +tls_sni
  35. tls_advertise_hosts = *
  36. # We test that $tls_in_sni is a valid domain, by an arbitrary email address foo@domain.tld .
  37. # Then, we extract the domain with a function that would fail if the email address is invalid.
  38. # If the certificate exists, we will use it, otherwise the default certificate in /etc/ssl will be used.
  39. tls_certificate = \
  40. ${if and {\
  41. { eq {${domain:foo@$tls_in_sni}} {$tls_in_sni}}\
  42. { exists{/usr/local/hestia/ssl/mail/$tls_in_sni.crt} }\
  43. }\
  44. {/usr/local/hestia/ssl/mail/$tls_in_sni.crt}\
  45. {/usr/local/hestia/ssl/certificate.crt}\
  46. }
  47. tls_privatekey = \
  48. ${if and {\
  49. { eq {${domain:foo@$tls_in_sni}} {$tls_in_sni}}\
  50. { exists{/usr/local/hestia/ssl/mail/$tls_in_sni.key} }\
  51. }\
  52. {/usr/local/hestia/ssl/mail/$tls_in_sni.key}\
  53. {/usr/local/hestia/ssl/certificate.key}\
  54. }
  55. daemon_smtp_ports = 25 : 465 : 587
  56. tls_on_connect_ports = 465
  57. tls_require_ciphers = PERFORMANCE:-RSA:-VERS-ALL:+VERS-TLS1.2:+VERS-TLS1.3:%SERVER_PRECEDENCE
  58. never_users = root
  59. host_lookup = *
  60. rfc1413_hosts = *
  61. rfc1413_query_timeout = 0s
  62. ignore_bounce_errors_after = 2d
  63. timeout_frozen_after = 7d
  64. DKIM_DOMAIN = ${lc:${domain:$h_from:}}
  65. DKIM_FILE = /etc/exim4/domains/${lc:${domain:$h_from:}}/dkim.pem
  66. DKIM_PRIVATE_KEY = ${if exists{DKIM_FILE}{DKIM_FILE}{0}}
  67. OUTGOING_IP = /etc/exim4/domains/$sender_address_domain/ip
  68. SMTP_RELAY_FILE = ${if exists{/etc/exim4/domains/${sender_address_domain}/smtp_relay.conf}{/etc/exim4/domains/$sender_address_domain/smtp_relay.conf}{/etc/exim4/smtp_relay.conf}}
  69. SMTP_RELAY_HOST = ${lookup{host}lsearch{SMTP_RELAY_FILE}}
  70. SMTP_RELAY_PORT = ${lookup{port}lsearch{SMTP_RELAY_FILE}}
  71. SMTP_RELAY_USER = ${lookup{user}lsearch{SMTP_RELAY_FILE}}
  72. SMTP_RELAY_PASS = ${lookup{pass}lsearch{SMTP_RELAY_FILE}}
  73. # Custom Filter
  74. system_filter = /etc/exim4/system.filter
  75. system_filter_user = Debian-exim
  76. ######################################################################
  77. # ACL CONFIGURATION #
  78. # Specifies access control lists for incoming SMTP mail #
  79. ######################################################################
  80. acl_not_smtp = acl_not_smtp
  81. begin acl
  82. # Limit per user for PHP scripts
  83. acl_not_smtp:
  84. deny message = Website of user $authenticated_id is sending too many emails - rate overlimit = $sender_rate / $sender_rate_period
  85. ratelimit = 200 / 1h / $authenticated_id
  86. warn ratelimit = 100 / 1h / strict / $authenticated_id
  87. log_message = Sender rate [limitlog]: log / account / $authenticated_id / $sender_rate / $sender_rate_period
  88. accept
  89. acl_check_spammers:
  90. accept hosts = +whitelist
  91. drop message = Your host in blacklist on this server.
  92. log_message = Host in blacklist
  93. hosts = +spammers
  94. accept
  95. acl_check_mail:
  96. deny condition = ${if eq{$sender_helo_name}{}}
  97. message = HELO required before MAIL
  98. drop !authenticated = *
  99. message = Helo name contains an IP address (HELO was $sender_helo_name) and not is valid
  100. condition = ${if match{$sender_helo_name}{\N((\d{1,3}[.-]\d{1,3}[.-]\d{1,3}[.-]\d{1,3})|([0-9a-f]{8})|([0-9A-F]{8}))\N}{yes}{no}}
  101. condition = ${if match {${lookup dnsdb{>: defer_never,ptr=$sender_host_address}}\}{$sender_helo_name}{no}{yes}}
  102. delay = 45s
  103. drop !authenticated = *
  104. condition = ${if isip{$sender_helo_name}}
  105. message = Access denied - Invalid HELO name (See RFC2821 4.1.3)
  106. drop !authenticated = *
  107. condition = ${if eq{[$interface_address]}{$sender_helo_name}}
  108. message = $interface_address is _my_ address
  109. accept
  110. acl_check_rcpt:
  111. accept hosts = :
  112. # Limit per email account for SMTP auhenticated users
  113. deny message = Email account $authenticated_id is sending too many emails - rate overlimit = $sender_rate / $sender_rate_period
  114. set acl_c_msg_limit = ${if exists{/etc/exim4/domains/${lookup{${domain:$authenticated_id}}dsearch{/etc/exim4/domains/}}/limits}{${lookup {$authenticated_id} lsearch{/etc/exim4/domains/${lookup{${domain:$authenticated_id}}dsearch{/etc/exim4/domains/}}/limits}{$value}{${readfile{/etc/exim4/limit.conf}}}}}{${readfile{/etc/exim4/limit.conf}}} }
  115. ratelimit = $acl_c_msg_limit / 1h / strict/ $authenticated_id
  116. warn ratelimit = ${eval:$acl_c_msg_limit / 2} / 1h / strict / $authenticated_id
  117. log_message = Sender rate [limitlog]: log / email / $authenticated_id / $sender_rate / $sender_rate_period
  118. deny message = Restricted characters in address
  119. domains = +local_domains
  120. local_parts = ^[.] : ^.*[@%!/|]
  121. deny message = Restricted characters in address
  122. domains = !+local_domains
  123. local_parts = ^[./|] : ^.*[@%!] : ^.*/\\.\\./
  124. require verify = sender
  125. accept hosts = +relay_from_hosts
  126. control = submission
  127. accept authenticated = *
  128. control = submission/domain=
  129. deny message = Rejected because $sender_host_address is in a black list at $dnslist_domain\n$dnslist_text
  130. hosts = !+whitelist
  131. dnslists = ${readfile {/etc/exim4/dnsbl.conf}{:}}
  132. require message = relay not permitted
  133. domains = +local_domains : +relay_to_domains
  134. deny message = smtp auth required
  135. sender_domains = +local_domains
  136. !authenticated = *
  137. require verify = recipient
  138. .ifdef CLAMD
  139. warn set acl_m0 = no
  140. warn condition = ${if exists {/etc/exim4/domains/$domain/antivirus}{yes}{no}}
  141. set acl_m0 = yes
  142. .endif
  143. .ifdef SPAMASSASSIN
  144. warn set acl_m1 = no
  145. set acl_m3 = no
  146. warn condition = ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
  147. set acl_m1 = yes
  148. warn condition = ${if exists {/etc/exim4/domains/$domain/reject_spam}{yes}{no}}
  149. set acl_m3 = yes
  150. .endif
  151. accept
  152. acl_check_data:
  153. .ifdef CLAMD
  154. deny message = Message contains a virus ($malware_name) and has been rejected
  155. malware = */defer_ok
  156. condition = ${if eq{$acl_m0}{yes}{yes}{no}}
  157. .endif
  158. .ifdef SPAMASSASSIN
  159. warn !authenticated = *
  160. hosts = !+relay_from_hosts
  161. condition = ${if < {$message_size}{1024K}}
  162. condition = ${if eq{$acl_m1}{yes}{yes}{no}}
  163. spam = debian-spamd:true/defer_ok
  164. add_header = X-Spam-Score: $spam_score_int
  165. add_header = X-Spam-Bar: $spam_bar
  166. add_header = X-Spam-Report: $spam_report
  167. set acl_m2 = $spam_score_int
  168. warn condition = ${if !eq{$acl_m2}{} {yes}{no}}
  169. condition = ${if >{$acl_m2}{SPAM_SCORE} {yes}{no}}
  170. add_header = X-Spam-Status: Yes
  171. message = SpamAssassin detected spam (from $sender_address to $recipients).
  172. # Deny spam at high score if spam score > SPAM_REJECT_SCORE and delete_spam is enabled
  173. deny message = This message scored $spam_score spam points
  174. spam = debian-spamd:true
  175. condition = ${if eq{$acl_m3}{yes}{yes}{no}}
  176. condition = ${if >{$spam_score_int}{SPAM_REJECT_SCORE}{1}{0}}
  177. .endif
  178. accept
  179. acl_check_mime:
  180. deny message = Blacklisted file extension detected
  181. condition = ${if match {${lc:$mime_filename}}{\N(\.ace|\.ade|\.adp|\.app|\.arj|\.asp|\.aspx|\.asx|\.bas|\.bat|\.cab|\.cer|\.chm|\.cmd|\.cnt|\.com|\.cpl|\.crt|\.csh|\.der|\.diagcab|\.dll|\.efi|\.exe|\.fla|\.fon|\.fxp|\.gadget|\.grp|\.hlp|\.hpj|\.hta|\.htc|\.img|\.inf|\.ins|\.iso|\.isp|\.its|\.jar|\.jnlp|\.js|\.jse|\.ksh|\.lib|\.lnk|\.mad|\.maf|\.mag|\.mam|\.maq|\.mar|\.mas|\.mat|\.mau|\.mav|\.maw|\.mcf|\.mda|\.mdb|\.mde|\.mdt|\.mdw|\.mdz|\.msc|\.msh|\.msh1|\.msh1xml|\.msh2|\.msh2xml|\.mshxml|\.msi|\.msp|\.mst|\.msu|\.ops|\.osd|\.pcd|\.pif|\.pl|\.plg|\.prf|\.prg|\.printerexport|\.ps1|\.ps1xml|\.ps2|\.ps2xml|\.psc1|\.psc2|\.psd1|\.psdm1|\.pst|\.py|\.pyc|\.pyo|\.pyw|\.pyz|\.pyzw|\.reg|\.scf|\.scr|\.sct|\.sfx|\.shb|\.shs|\.swf|\.sys|\.theme|\.tmp|\.ttf|\.url|\.vb|\.vba|\.vbe|\.vbp|\.vbs|\.vhd|\.vhdx|\.vsmacros|\.vsw|\.vxd|\.webpnp|\.website|\.wim|\.ws|\.wsc|\.wsf|\.wsh|\.xbap|\.xll|\.xnk)$\N}{1}{0}}
  182. accept
  183. ######################################################################
  184. # AUTHENTICATION CONFIGURATION #
  185. ######################################################################
  186. begin authenticators
  187. smtp_relay_login:
  188. driver = plaintext
  189. public_name = LOGIN
  190. hide client_send = : SMTP_RELAY_USER : SMTP_RELAY_PASS
  191. dovecot_plain:
  192. driver = dovecot
  193. public_name = PLAIN
  194. server_socket = /run/dovecot/auth-client
  195. server_set_id = $auth1
  196. dovecot_login:
  197. driver = dovecot
  198. public_name = LOGIN
  199. server_socket = /run/dovecot/auth-client
  200. server_set_id = $auth1
  201. ######################################################################
  202. # ROUTERS CONFIGURATION #
  203. # Specifies how addresses are handled #
  204. ######################################################################
  205. begin routers
  206. send_via_unauthenticated_smtp_relay:
  207. driver = manualroute
  208. address_data = SMTP_RELAY_HOST:SMTP_RELAY_PORT
  209. domains = !+local_domains
  210. require_files = SMTP_RELAY_FILE
  211. condition = ${if eq{SMTP_RELAY_USER}{}}
  212. transport = remote_smtp
  213. route_list = * ${extract{1}{:}{$address_data}}::${extract{2}{:}{$address_data}}
  214. no_more
  215. no_verify
  216. send_via_smtp_relay:
  217. driver = manualroute
  218. address_data = SMTP_RELAY_HOST:SMTP_RELAY_PORT
  219. domains = !+local_domains
  220. require_files = SMTP_RELAY_FILE
  221. transport = smtp_relay_smtp
  222. route_list = * ${extract{1}{:}{$address_data}}::${extract{2}{:}{$address_data}}
  223. no_more
  224. no_verify
  225. dnslookup:
  226. driver = dnslookup
  227. domains = !+local_domains
  228. transport = remote_smtp
  229. no_more
  230. userforward:
  231. driver = redirect
  232. check_local_user
  233. file = $home/.forward
  234. require_files = ${local_part}:+${home}/.forward
  235. domains = +local_domains
  236. allow_filter
  237. no_verify
  238. no_expn
  239. check_ancestor
  240. file_transport = address_file
  241. pipe_transport = address_pipe
  242. reply_transport = address_reply
  243. procmail:
  244. driver = accept
  245. check_local_user
  246. require_files = ${local_part}:+${home}/.procmailrc:/usr/bin/procmail
  247. transport = procmail
  248. no_verify
  249. autoreplay:
  250. driver = accept
  251. require_files = /etc/exim4/domains/$domain/autoreply.${local_part}.msg
  252. condition = ${if exists{/etc/exim4/domains/$domain/autoreply.${local_part}.msg}{yes}{no}}
  253. retry_use_local_part
  254. transport = userautoreply
  255. unseen
  256. aliases:
  257. driver = redirect
  258. headers_add = X-redirected: yes
  259. data = ${extract{1}{:}{${lookup{$local_part@$domain}lsearch{/etc/exim4/domains/$domain/aliases}}}}
  260. require_files = /etc/exim4/domains/$domain/aliases
  261. redirect_router = dnslookup
  262. pipe_transport = address_pipe
  263. unseen
  264. localuser_fwd_only:
  265. driver = accept
  266. transport = devnull
  267. condition = ${if exists{/etc/exim4/domains/$domain/fwd_only}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/fwd_only}{true}{false}}}}
  268. localuser_spam:
  269. driver = accept
  270. transport = local_spam_delivery
  271. condition = ${if eq {${if match{$h_X-Spam-Status:}{\N^Yes\N}{yes}{no}}} {${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}{yes}{no_such_user}}}}
  272. localuser:
  273. driver = accept
  274. transport = local_delivery
  275. condition = ${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}{true}{false}}
  276. catchall:
  277. driver = redirect
  278. headers_add = X-redirected: yes
  279. require_files = /etc/exim4/domains/$domain/aliases
  280. data = ${extract{1}{:}{${lookup{*@$domain}lsearch{/etc/exim4/domains/$domain/aliases}}}}
  281. file_transport = local_delivery
  282. redirect_router = dnslookup
  283. condition = ${lookup{$local_part@$domain}lsearch{/etc/exim4/domains/${lookup{$domain}dsearch{/etc/exim4/domains/}}/aliases}{false}{true}}
  284. terminate_alias:
  285. driver = accept
  286. transport = devnull
  287. condition = ${lookup{$local_part@$domain}lsearch{/etc/exim4/domains/$domain/aliases}{true}{false}}
  288. ######################################################################
  289. # TRANSPORTS CONFIGURATION #
  290. ######################################################################
  291. begin transports
  292. smtp_relay_smtp:
  293. driver = smtp
  294. hosts_require_auth = $host_address
  295. hosts_require_tls = $host_address
  296. remote_smtp:
  297. driver = smtp
  298. helo_data = ${lookup dnsdb{>: defer_never,ptr=$sending_ip_address}{${listextract{1}{$value}}}{$primary_hostname}}
  299. dkim_domain = DKIM_DOMAIN
  300. dkim_selector = mail
  301. dkim_private_key = DKIM_PRIVATE_KEY
  302. dkim_canon = relaxed
  303. dkim_strict = 0
  304. hosts_try_fastopen = !*.l.google.com
  305. interface = ${if exists{OUTGOING_IP}{${readfile{OUTGOING_IP}}}}
  306. procmail:
  307. driver = pipe
  308. command = "/usr/bin/procmail -d $local_part"
  309. return_path_add
  310. delivery_date_add
  311. envelope_to_add
  312. user = $local_part
  313. initgroups
  314. return_output
  315. local_delivery:
  316. driver = appendfile
  317. maildir_format
  318. maildir_use_size_file
  319. user = ${extract{2}{:}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}}}}
  320. group = mail
  321. create_directory
  322. directory_mode = 770
  323. mode = 660
  324. use_lockfile = no
  325. delivery_date_add
  326. envelope_to_add
  327. return_path_add
  328. directory = "${extract{5}{:}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}}}}/mail/$domain/$local_part"
  329. quota = ${extract{6}{:}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}}}}M
  330. quota_warn_threshold = 75%
  331. local_spam_delivery:
  332. driver = appendfile
  333. maildir_format
  334. maildir_use_size_file
  335. user = ${extract{2}{:}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}}}}
  336. group = mail
  337. create_directory
  338. directory_mode = 770
  339. mode = 660
  340. use_lockfile = no
  341. delivery_date_add
  342. envelope_to_add
  343. return_path_add
  344. directory = "${extract{5}{:}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}}}}/mail/$domain/$local_part/.Spam"
  345. quota = ${extract{6}{:}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}}}}M
  346. quota_directory = "${extract{5}{:}{${lookup{$local_part}lsearch{/etc/exim4/domains/$domain/passwd}}}}/mail/$domain/$local_part"
  347. quota_warn_threshold = 75%
  348. address_pipe:
  349. driver = pipe
  350. return_output
  351. address_file:
  352. driver = appendfile
  353. delivery_date_add
  354. envelope_to_add
  355. return_path_add
  356. address_reply:
  357. driver = autoreply
  358. userautoreply:
  359. driver = autoreply
  360. file = /etc/exim4/domains/$domain/autoreply.${local_part}.msg
  361. from = "${local_part}@${domain}"
  362. headers = Content-Type: text/plain; charset=utf-8;\nContent-Transfer-Encoding: 8bit
  363. subject = "${if def:h_Subject: {Autoreply: \"${rfc2047:$h_Subject:}\"} {Autoreply Message}}"
  364. to = "${sender_address}"
  365. devnull:
  366. driver = appendfile
  367. file = /dev/null
  368. ######################################################################
  369. # RETRY CONFIGURATION #
  370. ######################################################################
  371. begin retry
  372. # Address or Domain Error Retries
  373. # ----------------- ----- -------
  374. * * F,2h,15m; G,16h,1h,1.5; F,4d,6h
  375. ######################################################################
  376. # REWRITE CONFIGURATION #
  377. ######################################################################
  378. begin rewrite
  379. ######################################################################