getmail & rspamc #4348
-
Another question regarding the integration of rspamd / rspamc with getmail. Do i need to add the necessary filter to the Getmail config, like from the getmail6 described here for spamassassin or where is rspamd integrated into the process when i use getmail for retrieval and /dovecot/deliver for local delivery?
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
I think @casperklein uses Amavis + SpamAssassin, and @georglauterbach uses rspamd. Not sure if either maintainer uses Getmail, as that was a community contributed alternative to fetchmail motivated by xoauth2 support I think. If the getmail docs cover it, it may be possible to have it deliver mail to Postfix instead of directly handing off to Dovecot. There would be three options there I think.
Getmail docs may refer to a relay option where you can provide a mail server to connect to and deliver mail to port 25 or 587/465, which I assume like the MDA delivery allows for changing the recipient address. With DMS port 587/465 will allow you to have any sender address provided you don't have Alternatively instead of handing off to Postfix and using the existing anti-spam integration we have, you could try integrate getmail with the anti-spam service directly (as you're requesting with |
Beta Was this translation helpful? Give feedback.
-
To be honest, I have no idea as I am not using getmail. Where did you get the information about the configuration you posted? I may be able to quickly read up on it (no promises though). |
Beta Was this translation helpful? Give feedback.
-
SolutionThe easiest approach is adjusting the Getmail config for This will always have the retrieved mail delivered to Dovecot regardless of rspamd scan results, but you can use Sieve rules on the rspamd added headers if you need more than automatic migration to mailbox Junk folder (triggered by Adapting from the example I gave in the related getmail discussion, this one modifies services:
dms-getmail:
image: ghcr.io/docker-mailserver/docker-mailserver:edge # (will become :15.0)
hostname: mail.example.test
environment:
ENABLE_GETMAIL: 1
# We only change this setting to 1 minute for quicker testing:
GETMAIL_POLL: 1
# Enable Rspamd + Disable equivalent default services it replaces:
ENABLE_RSPAMD: 1
ENABLE_AMAVIS: 0
ENABLE_OPENDKIM: 0
ENABLE_OPENDMARC: 0
ENABLE_POLICYD_SPF: 0
# Anti-virus support (rspamd integrated),
# NOTE: that rspamc command may fail early into container startup until clamav is actually ready.
ENABLE_CLAMAV: 1
# You'd normally use `volumes` here but for simplicity of the example, all config is contained within `compose.yaml`:
configs:
- source: dms-accounts-getmail
target: /tmp/docker-mailserver/postfix-accounts.cf
- source: getmail-jane
target: /tmp/docker-mailserver/getmail/jane.cf
dms-remote:
image: ghcr.io/docker-mailserver/docker-mailserver:edge
hostname: mail.remote.test
environment:
# Allows for us send a test mail easily by trusting any mail client run within this container (`swaks`):
PERMIT_DOCKER: container
configs:
- source: dms-accounts-remote
target: /tmp/docker-mailserver/postfix-accounts.cf
# Using the Docker Compose `configs.content` feature instead of volume mounting separate files.
# NOTE: This feature requires Docker Compose v2.23.1 (Nov 2023) or newer:
# https://github.com/compose-spec/compose-spec/pull/446
configs:
# Basic getmail config to retrieve mail from an account at another mail server via IMAP credentials:
getmail-jane:
content: |
[retriever]
# To minimize config, this example will instead use port 143 without TLS verification:
#type = SimpleIMAPSSLRetriever
type = SimpleIMAPRetriever
server = mail.remote.test
username = [email protected]
password = secret
[destination]
type = MDA_external
allow_root_commands = true
path = /usr/bin/rspamc
arguments = ("--mime", "--hostname", "localhost", "--exec", "/usr/lib/dovecot/deliver -d [email protected]")
# DMS requires an account to complete setup, provide one for each DMS instance:
# NOTE:
# - Both accounts are configured with the same password `secret` (SHA512-CRYPT hashed).
# - To opt-out of Docker Compose variable interpolation, `$` must be escaped as `$$`.
dms-accounts-getmail:
content: |
[email protected]|{SHA512-CRYPT}$$6$$sbgFRCmQ.KWS5ryb$$EsWrlYosiadgdUOxCBHY0DQ3qFbeudDhNMqHs6jZt.8gmxUwiLVy738knqkHD4zj4amkb296HFqQ3yDq4UXt8.
dms-accounts-remote:
content: |
[email protected]|{SHA512-CRYPT}$$6$$sbgFRCmQ.KWS5ryb$$EsWrlYosiadgdUOxCBHY0DQ3qFbeudDhNMqHs6jZt.8gmxUwiLVy738knqkHD4zj4amkb296HFqQ3yDq4UXt8. NOTE: By default if Testing example and breakdownYou can use docker compose exec dms-remote swaks \
--server mail.remote.test \
--port 25 \
--from [email protected] \
--to [email protected] \
--attach 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' Which delivers a mail like this: Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: from mail.remote.test
by mail.remote.test with LMTP
id fWUSFyyHpmcYBAAA88HVfQ
(envelope-from <[email protected]>)
for <[email protected]>; Fri, 07 Feb 2025 22:20:28 +0000
Received: from localhost (localhost [127.0.0.1])
by mail.remote.test (Postfix) with ESMTP id 4905B182940
for <[email protected]>; Fri, 7 Feb 2025 22:20:28 +0000 (UTC)
Received: from mail.remote.test (mail.remote.test [172.19.0.2])
by mail.remote.test (Postfix) with ESMTP id A710B181CEE
for <[email protected]>; Fri, 7 Feb 2025 22:20:27 +0000 (UTC)
Date: Fri, 07 Feb 2025 22:20:27 +0000
To: [email protected]
From: [email protected]
Subject: test Fri, 07 Feb 2025 22:20:27 +0000
Message-Id: <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_MIME_BOUNDARY_000_1031"
------=_MIME_BOUNDARY_000_1031
Content-Type: text/plain
This is a test mailing
------=_MIME_BOUNDARY_000_1031
Content-Type: application/octet-stream
Content-Disposition: attachment
Content-Transfer-Encoding: BASE64
WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5EQVJELUFOVElWSVJVUy1URVNU
LUZJTEUhJEgrSCo=
------=_MIME_BOUNDARY_000_1031-- When X-getmail-retrieved-from-mailbox: INBOX For reference if set the general options
With the getmail X-Spam-Scanner: rspamc 3.11.0
X-Spam-Scan-Time: 0.59
X-Spam: yes
X-Spam-Action: reject
X-Spam-Score: 9.00 / 11.00
X-Spam-Level: *********
X-Spam-Symbols: HFILTER_HOSTNAME_UNKNOWN,
FROM_EQ_ENVFROM,
HFILTER_FROMHOST_NORES_A_OR_MX,
TO_DN_NONE,
PREVIOUSLY_DELIVERED,
CLAM_VIRUS,
RECEIVED_HELO_LOCALHOST,
MIME_GOOD,
RCVD_COUNT_THREE,
DMARC_NA,
R_DKIM_NA,
ARC_NA,
FROM_NO_DN,
MISSING_XM_UA,
MIME_TRACE,
RCVD_NO_TLS_LAST,
RCPT_COUNT_ONE,
HAS_ATTACHMENT With the We could probably add a sieve rule for TroubleshootingReference: This may be more convenient for testing We can create a file similar to the email content From: Docker Mail Server <[email protected]>
To: Existing Local User <[email protected]>
Date: Sat, 22 May 2010 01:23:45 -0000
Subject: Test Message
Message-Id: <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="emailboundary"
This is a multi-part message in MIME format with the EICAR virus.
--emailboundary
Content-Type: text/plain
This is the body of the message.
--emailboundary
Content-Type: application/octet-stream
Content-Disposition: attachment
Content-Transfer-Encoding: BASE64
H4sIAAAAAAAAA4sw9VcMUHVwDIg2iQmIijA10QiI0zR3dtY0r1Vx9XR2DNINDnH0c3EMctF19Avx
DPMMCg3WDXENDtF18/RxVVTx0PbQ4gIA2yvQHUUAAAA=
--emailboundary-- Now you can run $ rspamc --hostname localhost /tmp/example-eicar.eml
Results for file: stdin (0.625 seconds)
[Metric: default]
Action: reject
Spam: true
Score: 2.50 / 11.00
Symbol: ARC_NA (0.00)
Symbol: CLAM_VIRUS (0.00)[Eicar-Signature]
Symbol: DATE_IN_PAST (1.00)[129045]
Symbol: DMARC_NA (0.50)[remote.test]
Symbol: FROM_HAS_DN (0.00)
Symbol: MIME_GOOD (-0.10)[text/plain]
Symbol: MIME_TRACE (0.00)[0:+]
Symbol: MISSING_XM_UA (0.00)
Symbol: ONCE_RECEIVED (0.10)
Symbol: RCPT_COUNT_ONE (0.00)[1]
Symbol: RCVD_COUNT_ZERO (0.00)[0]
Symbol: R_DKIM_NA (1.00)
Symbol: TO_DN_ALL (0.00)
Message-ID: [email protected]
Message - smtp_message: ClamAV FOUND VIRUS "Eicar-Signature" Without # You can also provide the mail content via STDIN like shown here,
# `--mime` will output the mail with updated headers to STDOUT:
$ rspamc --mime --hostname localhost < /tmp/example-eicar.eml
From: Docker Mail Server <[email protected]>
To: Existing Local User <[email protected]>
Date: Sat, 22 May 2010 01:23:45 -0000
Subject: Test Message
Message-Id: <[email protected]>
X-Spam-Scanner: rspamc 3.11.0
X-Spam-Scan-Time: 0.647
X-Spam: yes
X-Spam-Action: reject
X-Spam-Score: 2.50 / 11.00
X-Spam-Level: ***
X-Spam-Symbols: DATE_IN_PAST,
FROM_HAS_DN,
TO_DN_ALL,
CLAM_VIRUS,
DMARC_NA,
MIME_GOOD,
R_DKIM_NA,
RCVD_COUNT_ZERO,
ONCE_RECEIVED,
ARC_NA,
RCPT_COUNT_ONE,
MISSING_XM_UA,
MIME_TRACE
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="emailboundary"
This is a multi-part message in MIME format with the EICAR virus.
--emailboundary
Content-Type: text/plain
This is the body of the message.
--emailboundary
Content-Type: application/octet-stream
Content-Disposition: attachment
Content-Transfer-Encoding: BASE64
H4sIAAAAAAAAA4sw9VcMUHVwDIg2iQmIijA10QiI0zR3dtY0r1Vx9XR2DNINDnH0c3EMctF19Avx
DPMMCg3WDXENDtF18/RxVVTx0PbQ4gIA2yvQHUUAAAA=
--emailboundary-- So despite So we configure Getmail with the extra
Without the EICAR contentJust for additional reference: From: Docker Mail Server <[email protected]>
To: Existing Local User <[email protected]>
Date: Sat, 22 May 2010 01:23:45 -0000
Subject: Test Message
Message-Id: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
This is the body of the message. No virus will be flagged now, nor is the hostname an issue, so the score is low enough for the action to be set as $ rspamc --hostname localhost /tmp/example.eml
Results for file: stdin (1.02 seconds)
[Metric: default]
Action: no action
Spam: false
Score: 2.50 / 11.00
Symbol: ARC_NA (0.00)
Symbol: DATE_IN_PAST (1.00)[129046]
Symbol: DBL_BLOCKED_OPENRESOLVER (0.00)[localhost:rdns, mail.remote.test:mid]
Symbol: DMARC_NA (0.50)[remote.test]
Symbol: FROM_HAS_DN (0.00)
Symbol: MIME_GOOD (-0.10)[text/plain]
Symbol: MIME_TRACE (0.00)[0:+]
Symbol: MISSING_XM_UA (0.00)
Symbol: ONCE_RECEIVED (0.10)
Symbol: RCPT_COUNT_ONE (0.00)[1]
Symbol: RCVD_COUNT_ZERO (0.00)[0]
Symbol: R_DKIM_NA (1.00)
Symbol: TO_DN_ALL (0.00)
Message-ID: [email protected] Without the hostname arg, the $ rspamc /tmp/example.eml
Results for file: stdin (0.025 seconds)
[Metric: default]
Action: add header
Spam: true
Score: 8.50 / 11.00
Symbol: ARC_NA (0.00)
Symbol: DATE_IN_PAST (1.00)[129046]
Symbol: DBL_BLOCKED_OPENRESOLVER (0.00)[mail.remote.test:mid]
Symbol: DMARC_NA (0.50)[remote.test]
Symbol: FROM_HAS_DN (0.00)
Symbol: HFILTER_HOSTNAME_UNKNOWN (6.00)
Symbol: MIME_GOOD (-0.10)[text/plain]
Symbol: MIME_TRACE (0.00)[0:+]
Symbol: MISSING_XM_UA (0.00)
Symbol: ONCE_RECEIVED (0.10)
Symbol: RCPT_COUNT_ONE (0.00)[1]
Symbol: RCVD_COUNT_ZERO (0.00)[0]
Symbol: R_DKIM_NA (1.00)
Symbol: TO_DN_ALL (0.00)
Message-ID: [email protected] |
Beta Was this translation helpful? Give feedback.
-
thanks to your guidance i am running DMS / RSpam now "in real life" deployment, with Snappymail as webmailer on top and soon a borg / borgmatic container in the stack for backup. For me this is the perfect setup, since i dont want the hassle of directly receiving and sending the mail but using getmail and smtp relay. Thanks again and when i have some time i will try to make a writeup on the complete "DMS Mailcollector" setup. |
Beta Was this translation helpful? Give feedback.
Solution
The easiest approach is adjusting the Getmail config for
[destination]
, not bothering with any of the alternative filter config (which would be more cumbersome in this case).This will always have the retrieved mail delivered to Dovecot regardless of rspamd scan results, but you can use Sieve rules on the rspamd added headers if you need more than automatic migration to mailbox Junk folder (triggered by
X-Spam: yes
).Adapting from the example I gave in the related getmail discussion, this one modifies
dms-getmail
to use rspamd + clamav, and I disregard the TLS setup, so all a singlecompose.yaml
: