exim4.conf.template 15 KB

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