6. 配置 Postfix

Postfix 需要两个主要的配置文件main.cfmaster.cf。 两者都需要您注意。

6.1. master.cf

您只需要更改一行

flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}

flags= user=cyrus argv=/usr/cyrus/bin/deliver -r ${sender} -m ${extension} ${user}

这个更改会影响什么?

查看 cyrus 手册页 man deliver 可以澄清这个问题

Postfix 默认设置使用了错误的 cyrus deliver 路径,这是第一个更改。参数 “-r” 插入了正确的返回路径。如果没有这个参数,被 sieve 拒绝/退回的邮件将被发送到您域的 cyrus 用户。

6.2. main.cf

在这里您需要更改更多内容,例如主机名、中继、别名查找等。

首先更改主机名

myhostname = foo.bar.org

mydestination

在这里您必须放入所有本地域名(对应于 sendmail 的/etc/mail/sendmail.cw)。 如果您有多个域名,请用逗号分隔它们。

mydestination = foo.bar.org, example.com, furchbar-grausam.ch, 
 whatever.domain.tld, mysql:/etc/postfix/mysql-mydestination.cf

Relayhost

在这里您定义外发邮件的传递位置。如果您不提供任何主机,邮件将直接传递到目标 smtp 主机。通常,您的 relayhosts 是您的互联网服务提供商的 smtp 服务器。

relayhost = relay01.foobar.net relay02.foobar.net relay03.foobar.net

Mailtransport

在这里您定义应如何处理为本地传递接受的邮件。在您的情况下,邮件应由 cyrus delivery 程序传递。

mailbox_transport = cyrus

在文件末尾您需要添加

virtual_alias_maps = hash:/etc/postfix/virtual, mysql:/etc/postfix/mysql-virtual.cf

如果您不想使用覆盖的 /etc/postfix/virtual,请跳过哈希条目

外发地址应从 test0002 at domain 重写为 user.name at virtualhost.com。如果您想使用 webmail 界面,这一点很重要。

sender_canonical_maps = mysql:/etc/postfix/mysql-canonical.cf 

现在您需要创建文件/etc/postfix/mysql-virtual.cf:

#
# mysql config file for alias lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mail

# the table name
table = virtual

#
select_field = dest
where_field = alias
additional_conditions = and status = '1'

文件/etc/postfix/mysql-canonical.cf:

# mysql config file for canonical lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mail

# the table name
table = virtual
#
select_field = alias
where_field = username
# Return the first match only
additional_conditions = and status = '1' limit 1

最后是文件/etc/postfix/mysql-mydestination.cf:

# mysql config file for local domain (like sendmail's sendmail.cw) lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mail

# the table name
table = domain
#
select_field = domain_name
where_field = domain_name

使用 SASL 和 PAM 进行 SMTP 身份验证

将以下内容放入您的/etc/postfix/main.cf

smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = 
broken_sasl_auth_clients = yes

您还需要创建文件/usr/local/lib/sasl2/smtpd.conf包含以下内容

pwcheck_method: saslauthd

下一步是告诉 postfix 如何找到 saslauthd 套接字

mv /var/run/sasl2 /var/run/sasl2-old
ln -s /var/run/saslauthd /var/run/sasl2

6.3. 对抗 SPAM

本节介绍如何使用 postfix 实现基本的 SPAM 防护设置。它不使用任何外部软件,例如 spamassassin 等。

Postfix 具有一些内置过滤器,允许您阻止明显的 SPAM 尝试。 特别是这些是