exim4.conf.template 14 KB

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