配置 postfix 将所有收到的邮件保存在文件中

配置 postfix 将所有收到的邮件保存在文件中

我正在尝试配置 postfix 以用于开发目的,对网站上的电子邮件进行验收测试。我基本完成了,但只有一件事我想正确设置,但不知道如何做。

目前,如果我的 postfix 服务器(在 docker 容器内)收到一封电子邮件,它会向/var/mail/root邮箱发送一条通知,告知邮件无法投递,如下所示:

$ 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

<[email protected]>: 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; [email protected]
Original-Recipient: rfc822;[email protected]
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 <[email protected]>; Fri,  9 Sep 2016 17:48:03 +0000 (UTC)

hhhhhhhhhhhhhhhhhhh

--0A7781416E0.1473443285/localhost--

这就是我了解从网站发送的电子邮件的方式。对我来说,这几乎没问题:我可以打开/var/mail/root测试,阅读其内容,确保正文、发件人和收件人正确。

不好的是,它不是实际发送到本地邮箱的邮件,而是一个发送失败的通知,恰好包含电子邮件的内容。我真正想要的是保存全部我的 postfix 服务器收到的邮件会集中到一个邮箱中,无论收件人头中的用户名是什么。以下是我的 postfix 服务器收到电子邮件时看到的内容:

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=<[email protected]>, 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

这是我当前的main.cf(可能有很多不必要的东西,请忽略它们):

# 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

我应该如何修改配置才能交付全部收到的邮件是否全部发送到单个邮箱?

答案1

我在我的配置中添加了以下内容:

always_bcc = root@localhost

现在 postfix 可以满足我的需要:它将所有收到的电子邮件保存在中/var/mail/root,并且这些电子邮件没有任何多余的文本。

相关内容