exim4.conf.template 16 KB

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