How can I use the Postfix setting always_bcc to forward mail for archiving purposes?
#4564
-
|
I have a need to send a copy of all incoming emails to my instance of docker-mailserver, to an address on the same instance. I have done the following in an attempt to accomplish this (I'm using dummy mail accounts in this example):
I assumed a copy would automatically be sent to [email protected], but unfortunately nothing is received, and I can't really get to grips of where I'm misunderstanding the outcome. Any help would be appreciated. :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
How did you restart? I have attempted to reproduce but everything appears working to me, so I will assume you did not restart your DMS container correctly (as we document in red at the start of our troubleshooting page). Here is a complete services:
dms:
image: ghcr.io/docker-mailserver/docker-mailserver:${DMS_RELEASE:-15.1.0}
hostname: mail.example.test
# These ENV are only to optimize the reproduction time:
environment:
# Amavis has some added overhead in startup and extra processing when mail arrives, disable:
ENABLE_AMAVIS: 0
# Trusting any client connection coming from within the container itself:
# (Delay appears to be about 6 seconds by postscreen upon receiving a connection from swaks, according to /var/log/mail.log)
PERMIT_DOCKER: container
# Avoid a startup delay caused by checking for new DMS release to notify by a mail sent to postmaster
# (which would have failed as postmaster is not configured either)
ENABLE_UPDATE_CHECK: 0
# The Docker Compose `configs` feature is a way to embed files into `compose.yaml`
# This is only used to bundle the whole example into a single `compose.yaml` file for reproductions
# Normally you'd prefer to use `volumes` instead with external files.
configs:
- source: dms-accounts
target: /tmp/docker-mailserver/postfix-accounts.cf
- source: dms-postfix-overrides
target: /tmp/docker-mailserver/postfix-main.cf
- source: test-bcc-works
target: /usr/local/bin/test-bcc-works
mode: 0755
# NOTE: In `compose.yaml` a `$` indicates a variable to replace with a host ENV value
# The content below contains `$` chars, which are escaped as `$$` to prevent being interpolated as ENV.
configs:
dms-accounts:
content: |
[email protected]|{SHA512-CRYPT}$$6$$sbgFRCmQ.KWS5ryb$$EsWrlYosiadgdUOxCBHY0DQ3qFbeudDhNMqHs6jZt.8gmxUwiLVy738knqkHD4zj4amkb296HFqQ3yDq4UXt8.
[email protected]|{SHA512-CRYPT}$$6$$sbgFRCmQ.KWS5ryb$$EsWrlYosiadgdUOxCBHY0DQ3qFbeudDhNMqHs6jZt.8gmxUwiLVy738knqkHD4zj4amkb296HFqQ3yDq4UXt8.
dms-postfix-overrides:
content: |
[email protected]
test-bcc-works:
content: |
#!/usr/bin/env bash
# Our test email that should also be received at our bcc-receiver mailbox:
swaks --silent --server localhost --from [email protected] --to [email protected] --body 'hello world'
# Allow a buffer of time to process mail by Postfix + Dovecot after swaks completes the delivery:
sleep 3
# Helper function for testing convenience:
function verify_mail_received_for() {
local RECIPIENT=$${1}
echo -e "\nChecking recipient: $${RECIPIENT}"
grep 'mail postfix/lmtp' /var/log/mail.log | grep --fixed-strings --silent "to=<$${RECIPIENT}@example.test>, relay=mail.example.test[/var/run/dovecot/lmtp]"
local POSTFIX_SENT=$${?}
grep 'mail dovecot' /var/log/mail.log | grep --fixed-strings "dovecot: lmtp($${RECIPIENT}@example.test)" | grep --fixed-strings --silent "stored mail into mailbox 'INBOX'"
local DOVECOT_RECEIVED=$${?}
if [[ $${POSTFIX_SENT} -eq 0 && $${DOVECOT_RECEIVED} -eq 0 ]]; then
echo 'Delivery successful'
# Outputs the number of mails in the mailbox accounts inbox:
doveadm mailbox status -u "$${RECIPIENT}@example.test" messages INBOX
else
echo 'Delivery failed'
fi
}
echo 'Checking inboxes for received test mail...'
verify_mail_received_for john.doe
verify_mail_received_for bcc-receiverWith the above # DMS may take about 5-10 seconds to start depending on host system:
$ docker compose up -d --force-recreate && sleep 10 && docker compose exec -it dms test-bcc-works
Checking inboxes for received test mail...
Checking recipient: john.doe
Delivery successful
INBOX messages=1
Checking recipient: bcc-receiver
Delivery successful
INBOX messages=1 |
Beta Was this translation helpful? Give feedback.
-
|
I tested your suggestion and it does indeed look like I can reproduce your results. As in, when running your suggested commands, I get similar output as yours. However, after having configured This got me thinking that it could have something to do with my current configuration in terms of aliases? I have a number of "catchall@[domain(s)]" aliases that worked just fine before adding the My "postfix-virtual.cf" file looks like the following (and this has been working very well for my purposes thus far, before this new venture of bcc:ing everything for archiving) I'm speculating that the emails that are supposed go to "[email protected]" are caught in the catchall rules. I have made a feeble attempt of adding If it's still unclear where the issue may be, I'll attempt at a more complete post that if nothing else could give a more complete view of my current setup. |
Beta Was this translation helpful? Give feedback.
How did you restart?
postfix-main.cfis only applied on container creation (initial setup).I have attempted to reproduce but everything appears working to me, so I will assume you did not restart your DMS container correctly (as we document in red at the start of our troubleshooting page).
Here is a complete
compose.yamlthat you can copy/paste and run.