Skip to content

Commit c9d1c43

Browse files
committed
improved ISPConfig mail
1 parent f6b38ed commit c9d1c43

File tree

2 files changed

+757
-661
lines changed

2 files changed

+757
-661
lines changed

config/exim4/exim4.conf.template

Lines changed: 174 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ MYSQL_BLACKTABLE=mail_blacklist
1515
# Server ID for Multiserver Setups
1616
MAILSERVER_ID=1
1717
MAILSERVER_HOSTNAME=mail.
18+
MAILSERVER_IP=192.168.0.108
1819
MAILSERVER_EXIM_BINARY=/usr/sbin/exim4
1920
MAILSERVER_SPAMC_BINARY=/usr/bin/spamc
2021

@@ -47,7 +48,7 @@ domainlist relay_to_domains = mysql;SELECT DISTINCT domain FROM MYSQL_DOMAINTABL
4748
hostlist relay_from_hosts = 127.0.0.1
4849
domainlist mmdomains = ${lookup mysql {SELECT domain FROM mail_mailman_domain}}
4950

50-
acl_smtp_rcpt = acl_check_rcpt
51+
# acl_smtp_rcpt = acl_check_rcpt
5152

5253
qualify_domain =
5354
# qualify_recipient =
@@ -92,8 +93,18 @@ tls_advertise_hosts = *
9293
# Require auth over SSL only.
9394
# auth_over_tls_hosts = *
9495

96+
helo_try_verify_hosts = !+relay_from_hosts
97+
98+
av_scanner = clamd:/var/run/clamav/clamd.ctl
9599
spamd_address = 127.0.0.1 783
96100

101+
acl_smtp_rcpt = acl_check_rcpt
102+
#acl_smtp_mail = acl_check_sender
103+
acl_smtp_connect = acl_check_host
104+
acl_smtp_data = acl_check_data
105+
acl_smtp_helo = acl_check_helo
106+
107+
97108
######################################################################
98109
# ACL CONFIGURATION #
99110
# Specifies access control lists for incoming SMTP mail #
@@ -102,36 +113,94 @@ spamd_address = 127.0.0.1 783
102113
begin acl
103114

104115
acl_check_rcpt:
116+
105117
accept hosts = :
118+
106119
deny domains = +local_domains
107120
local_parts = ^[.] : ^.*[@%!/|]
121+
108122
deny domains = !+local_domains
109123
local_parts = ^[./|] : ^.*[@%!] : ^.*/\\.\\./
124+
110125
accept local_parts = postmaster
111126
domains = +local_domains
127+
112128
require verify = sender
129+
130+
# Blacklist management
131+
deny senders = ${lookup mysql {SELECT DISTINCT address FROM MYSQL_BLACKTABLE WHERE '${quote_mysql:$sender_address}' LIKE address \
132+
AND (recipient = '' OR recipient = '${quote_mysql:$domain}' OR recipient = '${quote_mysql:$local_part}@${quote_mysql:$domain}') \
133+
AND active = '1' AND server_id = 'MAILSERVER_ID'}{$value}}
134+
log_message = Blacklisted. Sender: <$sender_address> Recipient: <$local_part@$domain>
135+
113136
accept domains = +local_domains
114137
endpass
115138
verify = recipient
139+
116140
accept domains = +relay_to_domains
117141
endpass
118142
verify = recipient
143+
119144
accept hosts = +relay_from_hosts
145+
120146
accept authenticated = *
147+
121148
deny message = relay not permitted
122149

150+
151+
acl_check_host:
152+
accept
153+
hosts = +relay_from_hosts
154+
#deny
155+
# log_message = match host_reject.list
156+
# hosts = /etc/exim4/filters/host_reject.list
157+
158+
accept
159+
160+
acl_check_helo:
161+
accept hosts = +relay_from_hosts
162+
# If the HELO pretend to be this host
163+
deny condition = ${if or { \
164+
{eq {${lc:$sender_helo_name}}{MAILSERVER_HOSTNAME}} \
165+
{eq {${lc:$sender_helo_name}}{MAILSERVER_IP}} \
166+
} {true}{false} }
167+
# by default we accept
168+
accept
169+
170+
123171
acl_check_data:
124-
warn message = X-Spam-Score: $spam_score ($spam_bar)
125-
spam = nobody:true
126-
warn message = X-Spam-Report: $spam_report
127-
spam = nobody:true
128-
warn message = Subject: *SPAM* $h_Subject
129-
spam = nobody
130172

131-
# reject spam at high scores (> 12)
132-
deny message = This message scored $spam_score spam points.
133-
spam = nobody:true
134-
condition = ${if >{$spam_score_int}{120}{1}{0}}
173+
accept hosts = +relay_from_hosts
174+
175+
# if there is a windows executable as attachment then we reject
176+
deny message = This message contains an attachment of a type which we do not accept (.$found_extension)
177+
demime = bat:btm:cmd:com:cpl:dll:exe:lnk:msi:pif:prf:reg:scr:vbs:url
178+
179+
# spamassassin
180+
warn message = X-SA-Score: $spam_score
181+
spam = nobody:true
182+
183+
warn message = X-SA-Report: $spam_report
184+
spam = nobody:true
185+
186+
condition = ${if >{$spam_score_int}{0}{true}{false}}
187+
warn message = X-SA-Status: Yes
188+
spam = nobody:true
189+
condition = ${if >{$spam_score_int}{50}{true}{false}}
190+
191+
deny message = This message scored $spam_score spam points.
192+
spam = nobody:true
193+
condition = ${if >{$spam_score_int}{70}{true}{false}}
194+
195+
# clamav
196+
deny message = This message contains a virus or other harmful content ($malware_name)
197+
demime = *
198+
malware = *
199+
log_message = Virus found in Message
200+
201+
# accept by default
202+
accept
203+
135204

136205

137206

@@ -176,13 +245,16 @@ dnslookup:
176245
ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8
177246
no_more
178247

179-
blacklist_router:
180-
driver = manualroute
181-
senders = ${lookup mysql {SELECT DISTINCT address FROM MYSQL_BLACKTABLE WHERE '${quote_mysql:$sender_address}' LIKE address}{$value}}
182-
condition = "${if !def:h_X-Spam-Flag: {1}{0}}"
183-
headers_add = X-Spam-Flag: YES
184-
route_list = * localhost
185-
self = pass
248+
# Blacklists werden jetzt in den ACL gepr�ft
249+
#blacklist_router:
250+
# driver = manualroute
251+
# senders = ${lookup mysql {SELECT DISTINCT address FROM MYSQL_BLACKTABLE WHERE '${quote_mysql:$sender_address}' LIKE address AND recipient = '${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}
252+
# # condition = "${if !def:h_X-Spam-Flag: {1}{0}}"
253+
# # headers_add = X-Spam-Flag: YES
254+
# route_list = * localhost
255+
# # self = pass
256+
# transport = devnull_transport
257+
# verify = false
186258

187259
#system_aliases:
188260
# driver = redirect
@@ -203,11 +275,11 @@ mysql_email_alias:
203275
driver = redirect
204276
allow_fail
205277
allow_defer
206-
data = ${lookup mysql{ SELECT destination FROM mail_redirect WHERE email='${local_part}@${domain}' AND type = 'alias'}}
278+
data = ${lookup mysql{ SELECT destination FROM mail_redirect WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}' AND type = 'alias'}}
207279

208280
mysql_email_forward:
209281
driver = redirect
210-
data = ${lookup mysql{ SELECT destination FROM mail_redirect WHERE email='${local_part}@${domain}' AND type = 'forward'}}
282+
data = ${lookup mysql{ SELECT destination FROM mail_redirect WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}' AND type = 'forward'}}
211283

212284
#spamcheck_router:
213285
# driver = manualroute
@@ -222,16 +294,53 @@ mysql_email_forward:
222294
# transport = spamcheck
223295
# verify = false
224296

297+
#spamdelete_router:
298+
# driver = manualroute
299+
# domains = ${lookup mysql {SELECT SUBSTRING_INDEX(email,'@',-1) FROM MYSQL_EMAILTABLE WHERE email=CONCAT('${quote_mysql:$local_part}','@','${quote_mysql:$domain}') AND spamdelete = '1'}{$value}}
300+
# # condition = "${if eq{$h_X-Spam-Flag:}{YES} {1}{0}}"
301+
# condition = "${if match{$h_X-Spam-Flag}{YES} {1}{0}}"
302+
# route_list = "* localhost byname"
303+
# transport = devnull_transport
304+
# verify = false
305+
306+
307+
spamrewrite_router:
308+
driver = manualroute
309+
domains = ${lookup mysql {SELECT SUBSTRING_INDEX(email,'@',-1) FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}
310+
senders = ! ${lookup mysql {SELECT DISTINCT MYSQL_WHITETABLE.address FROM MYSQL_WHITETABLE WHERE '${quote_mysql:$sender_address}' LIKE MYSQL_WHITETABLE.address}{$value}}
311+
condition = ${if and { \
312+
{>{$spam_score_int}{${lookup mysql {SELECT spam_rewrite_score_int FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}}}\
313+
{!eq {$received_protocol}{spam-rewrite}} \
314+
{!eq {$received_protocol}{local}} \
315+
}{true}{false}}
316+
headers_remove = Subject
317+
headers_add = Subject: ${lookup mysql {SELECT spam_rewrite_subject FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}} $header_subject
318+
route_list = "* localhost byname"
319+
transport = spamrewrite_transport
320+
verify = false
321+
322+
spamredirect_router:
323+
driver = manualroute
324+
domains = ${lookup mysql {SELECT SUBSTRING_INDEX(email,'@',-1) FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}
325+
senders = ! ${lookup mysql {SELECT DISTINCT MYSQL_WHITETABLE.address FROM MYSQL_WHITETABLE WHERE '${quote_mysql:$sender_address}' LIKE MYSQL_WHITETABLE.address}{$value}}
326+
condition = ${if >{$spam_score_int}{${lookup mysql {SELECT spam_redirect_score_int FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}}{true}{false}}
327+
route_list = "* localhost byname"
328+
transport = spamredirect_transport
329+
verify = false
330+
225331
spamdelete_router:
226332
driver = manualroute
227-
domains = ${lookup mysql {SELECT SUBSTRING_INDEX(email,'@',-1) FROM MYSQL_EMAILTABLE WHERE email=CONCAT('${quote_mysql:$local_part}','@','${quote_mysql:$domain}') AND spamdelete = '1'}{$value}}
228-
# condition = "${if eq{$h_X-Spam-Flag:}{YES} {1}{0}}"
229-
condition = "${if match{$h_X-Spam-Flag}{YES} {1}{0}}"
333+
domains = ${lookup mysql {SELECT SUBSTRING_INDEX(email,'@',-1) FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}
334+
senders = ! ${lookup mysql {SELECT DISTINCT MYSQL_WHITETABLE.address FROM MYSQL_WHITETABLE WHERE '${quote_mysql:$sender_address}' LIKE MYSQL_WHITETABLE.address}{$value}}
335+
condition = ${if and { \
336+
{>{$spam_score_int}{${lookup mysql {SELECT spam_delete_score_int FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}}}\
337+
{!eq {$received_protocol}{spam-rewrite}} \
338+
{!eq {$received_protocol}{local}} \
339+
}{true}{false}}
230340
route_list = "* localhost byname"
231341
transport = devnull_transport
232342
verify = false
233343

234-
235344
autoresponder_router:
236345
driver = accept
237346
domains = ${lookup mysql {SELECT SUBSTRING_INDEX(email,'@',-1) FROM MYSQL_EMAILTABLE WHERE email=CONCAT('${quote_mysql:$local_part}','@','${quote_mysql:$domain}') AND autoresponder='yes'}{$value}}
@@ -257,11 +366,6 @@ mysql_catchall_router:
257366
data=${lookup mysql{ SELECT destination FROM mail_domain_catchall WHERE domain='${domain}'}}
258367
allow_fail
259368
allow_defer
260-
261-
#domain_catchall_director:
262-
# driver = redirect
263-
# domains = ${lookup mysql {SELECT SUBSTRING_INDEX(email,'@',-1) FROM MYSQL_EMAILTABLE WHERE email=CONCAT('${quote_mysql:$local_part}','@') AND forward != ''}{$value}}
264-
# data = ${lookup mysql {SELECT forward FROM MYSQL_EMAILTABLE WHERE email=CONCAT('${quote_mysql:$local_part}','@') AND forward != ''}{$value}}
265369

266370
######################################################################
267371
# TRANSPORTS CONFIGURATION #
@@ -272,26 +376,16 @@ mysql_catchall_router:
272376

273377
begin transports
274378

379+
########################
380+
# Remote smtp transport
381+
########################
382+
275383
remote_smtp:
276384
driver = smtp
277385

278-
devnull_delivery:
279-
driver = appendfile
280-
file = /dev/null
281-
group = mail
282-
283-
address_pipe:
284-
driver = pipe
285-
return_output
286-
287-
address_file:
288-
driver = appendfile
289-
delivery_date_add
290-
envelope_to_add
291-
return_path_add
292-
293-
address_reply:
294-
driver = autoreply
386+
###################
387+
# Mailman transport
388+
###################
295389

296390
mailman_transport:
297391
driver = pipe
@@ -305,11 +399,15 @@ mailman_transport:
305399
user = ${lookup mysql{SELECT mm_user FROM mail_mailman_domain WHERE domain='${domain}'}}
306400
group = ${lookup mysql{SELECT mm_group FROM mail_mailman_domain WHERE domain='${domain}'}}
307401

308-
spamcheck:
402+
403+
#################################################################################
404+
# This transport is only for rewriting the header of the message with ***SPAM***
405+
#################################################################################
406+
407+
spamrewrite_transport:
309408
driver = pipe
310-
command = MAILSERVER_EXIM_BINARY -oMr spam-scanned -bS
409+
command = MAILSERVER_EXIM_BINARY -oMr spam-rewrite -bS
311410
use_bsmtp = true
312-
transport_filter = MAILSERVER_SPAMC_BINARY
313411
home_directory = "/tmp"
314412
current_directory = "/tmp"
315413
user = mail
@@ -320,6 +418,23 @@ spamcheck:
320418
message_prefix =
321419
message_suffix =
322420

421+
######################################################
422+
# This transport is only for redirecting SPAM messages
423+
######################################################
424+
425+
spamredirect_transport:
426+
driver = appendfile
427+
directory = ${lookup mysql {SELECT concat(spam_redirect_maildir,'/Maildir') FROM mail_spamfilter WHERE email='${quote_mysql:$local_part}@${quote_mysql:$domain}'}{$value}}
428+
maildir_format
429+
user = mail
430+
group = mail
431+
mode = 0660
432+
directory_mode = 0770
433+
434+
##########################
435+
# Local delivery transport
436+
##########################
437+
323438
local_delivery:
324439
driver = appendfile
325440
directory = ${lookup mysql {SELECT concat(maildir,'/Maildir') FROM MYSQL_EMAILTABLE WHERE email=CONCAT('${quote_mysql:$local_part}','@','${quote_mysql:$domain}')}{$value}}
@@ -328,7 +443,8 @@ local_delivery:
328443
group = mail
329444
quota = ${lookup mysql{select quota from MYSQL_EMAILTABLE where email=CONCAT('${quote_mysql:$local_part}','@','${quote_mysql:$domain}')}{${value}M}}
330445
quota_is_inclusive = false
331-
#quota_size_regex = ,S=(\d+):
446+
maildir_tag = ,S=$message_size
447+
quota_size_regex = ,S=(\d+):
332448
quota_warn_threshold = 75%
333449
maildir_use_size_file = false
334450
quota_warn_message = "To: $local_part@$domain\n\
@@ -340,20 +456,10 @@ local_delivery:
340456
Please take note of this and remove unwanted mail from your mailbox.\n"
341457
mode = 0660
342458
directory_mode = 0770
343-
344-
#mysql_delivery:
345-
# driver = appendfile
346-
# maildir_format
347-
# directory = \
348-
# ${lookup mysql{SELECT maildir FROM passwd \
349-
# WHERE email='${local_part}@${domain}'}}
350-
# user = \
351-
# ${lookup mysql{SELECT uid FROM passwd \
352-
# WHERE email='${local_part}@${domain}'}}
353-
# group = \
354-
# ${lookup mysql{SELECT gid FROM passwd \
355-
# WHERE email='${local_part}@${domain}'}}
356459

460+
##########################
461+
# autoresponder transport
462+
##########################
357463

358464
autoresponder_transport:
359465
driver = autoreply
@@ -362,11 +468,16 @@ autoresponder_transport:
362468
subject = "Autoresponder: ${local_part}@${domain}"
363469
text = ${lookup mysql {SELECT autoresponder_text FROM MYSQL_EMAILTABLE WHERE email=CONCAT('${quote_mysql:$local_part}','@','${quote_mysql:$domain}')}{$value}}
364470

471+
##########################
472+
# devnull transport
473+
##########################
474+
365475
devnull_transport:
366476
driver = appendfile
367477
file = /dev/null
368478
user = mail
369479

480+
370481
######################################################################
371482
# RETRY CONFIGURATION #
372483
######################################################################

0 commit comments

Comments
 (0)