1

I'm trying to configure postfix for development purposes, to do acceptance testing of emails on a web site. I'm mostly finished with it, however there is only one thing I want to set up correctly but don't know how to do.

Currently, if my postfix server (inside a docker container) receives an email, it puts a notification to /var/mail/root mailbox that a message couldn't be delivered, like this:

$ cat /var/mail/root
From MAILER-DAEMON  Fri Sep  9 17:48:05 2016
Return-Path: <>
X-Original-To: root@localhost
Delivered-To: root@localhost
Received: by localhost (Postfix)
        id 0209A1416E4; Fri,  9 Sep 2016 17:48:05 +0000 (UTC)
Date: Fri,  9 Sep 2016 17:48:05 +0000 (UTC)
From: MAILER-DAEMON@localhost (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
To: root@localhost
Auto-Submitted: auto-replied
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
        boundary="0A7781416E0.1473443285/localhost"
Message-Id: <20160909174805.0209A1416E4@localhost>

This is a MIME-encapsulated message.

--0A7781416E0.1473443285/localhost
Content-Description: Notification
Content-Type: text/plain; charset=us-ascii

This is the mail system at host localhost.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system

<hello@ya.ru>: unknown user: "hello"

--0A7781416E0.1473443285/localhost
Content-Description: Delivery report
Content-Type: message/delivery-status

Reporting-MTA: dns; localhost
X-Postfix-Queue-ID: 0A7781416E0
X-Postfix-Sender: rfc822; root@localhost
Arrival-Date: Fri,  9 Sep 2016 17:48:03 +0000 (UTC)

Final-Recipient: rfc822; hello@ya.ru
Original-Recipient: rfc822;hello@ya.ru
Action: failed
Status: 5.1.1
Diagnostic-Code: X-Postfix; unknown user: "hello"

--0A7781416E0.1473443285/localhost
Content-Description: Undelivered Message
Content-Type: message/rfc822

Return-Path: <root@localhost>
Received: from localhost (unknown [172.20.0.6])
        by localhost (Postfix) with ESMTP id 0A7781416E0
        for <hello@ya.ru>; Fri,  9 Sep 2016 17:48:03 +0000 (UTC)

hhhhhhhhhhhhhhhhhhh

--0A7781416E0.1473443285/localhost--

And that's how I know about the emails that have been sent from the website. For me this is almost fine: I can open /var/mail/root inside a test, read its contents, make sure that there are correct body, sender and recipient.

What is not fine is that it is not an acual mail delivery to a local mailbox, but a notification about a failed delivery that just happens to contain the content of the email. What I actually want is to just save all mail received by my postfix server into a single mailbox, regardless of the username in the recipient header. Here is what I see when my postfix server receives an email:

Sep  9 18:42:01 db59bdabd3ea postfix/smtpd[1455]: connect from unknown[172.20.0.6]
Sep  9 18:42:01 db59bdabd3ea postfix/smtpd[1455]: 7B8CF1416E0: client=unknown[172.20.0.6]
Sep  9 18:42:03 db59bdabd3ea postfix/cleanup[1458]: 7B8CF1416E0: message-id=<>
Sep  9 18:42:03 db59bdabd3ea postfix/qmgr[110]: 7B8CF1416E0: from=<root@localhost>, size=170, nrcpt=1 (queue active)
Sep  9 18:42:03 db59bdabd3ea postfix/smtpd[1455]: disconnect from unknown[172.20.0.6]
Sep  9 18:42:03 db59bdabd3ea postfix/local[1459]: 7B8CF1416E0: to=<ya@ya.ru>, relay=local, delay=2.1, delays=2.1/0.01/0/0.02, dsn=5.1.1, status=bounced (unknown user: "ya")
Sep  9 18:42:03 db59bdabd3ea postfix/cleanup[1458]: 908DE1416E4: message-id=<20160909184203.908DE1416E4@localhost>
Sep  9 18:42:03 db59bdabd3ea postfix/bounce[1460]: 7B8CF1416E0: sender non-delivery notification: 908DE1416E4
Sep  9 18:42:03 db59bdabd3ea postfix/qmgr[110]: 908DE1416E4: from=<>, size=1824, nrcpt=1 (queue active)
Sep  9 18:42:03 db59bdabd3ea postfix/qmgr[110]: 7B8CF1416E0: removed
Sep  9 18:42:03 db59bdabd3ea postfix/local[1459]: 908DE1416E4: to=<root@localhost>, relay=local, delay=0.01, delays=0.01/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Sep  9 18:42:03 db59bdabd3ea postfix/qmgr[110]: 908DE1416E4: removed

Here is my current main.cf (there are probably a lot of unnecessary things, please ignore them):

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=no
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = pcre:/etc/postfix/mydestinations
local_recipient_maps =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

defer_transports = smtp
#smtpd_sender_restrictions = static:HOLD

relayhost =
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = 
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_use_tls = yes
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy

How should I modify the config to deliver all the received mail to a single mailbox?

1

I added the following to my config:

always_bcc = root@localhost

Now postfix does what I needed: it saves all the received emails in /var/mail/root, and those emails don't have any extra text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.