Postfix 需要两个主要的配置文件main.cf和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 用户。
在这里您需要更改更多内容,例如主机名、中继、别名查找等。
首先更改主机名
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 |
本节介绍如何使用 postfix 实现基本的 SPAM 防护设置。它不使用任何外部软件,例如 spamassassin 等。
Postfix 具有一些内置过滤器,允许您阻止明显的 SPAM 尝试。 特别是这些是
smtpd_helo_required = yes
在main.cf中的这个开关意味着连接到您的邮件服务器的 SMTP 客户端必须在连接时给出 “helo”。
smtpd_recipient_restrictions
在main.cf中的这个选项允许您定义关于处理邮件接受的不同规则。 以下示例仅拒绝所有无效的发件人和收件人数据。 此外,它还定义了如何从在线黑名单中查找已知的垃圾邮件发送者。
smtpd_recipient_restrictions = reject_invalid_hostname, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_unauth_pipelining, permit_mynetworks, reject_unauth_destination, reject_rbl_client zombie.dnsbl.sorbs.net, reject_rbl_client relays.ordb.org, reject_rbl_client opm.blitzed.org, reject_rbl_client list.dsbl.org, reject_rbl_client sbl.spamhaus.org, permit |
mime_header_checks=pcre:/etc/postfix/body_checks
MIME 标头检查允许您拒绝包含恶意 MIME 内容的邮件,即危险的附件,例如 Windows 可执行文件。 创建文件/etc/postfix/body_checks。 以下示例拒绝所有包含潜在危险附件的邮件。 根据我的经验,使用此示例将过滤掉通过电子邮件传递的大多数病毒。 在任何情况下,都应始终安装病毒扫描器。
/^((Content-(Disposition: attachment;|Type:).*|\ +)| *)(file)?name\ *=\ *"?.*\.(lnk|asd|hlp|ocx|reg|bat|c[ho]m|cmd|exe|dll|vxd|pif|scr|hta|jse?|sh[mbs]|vb[esx]|ws[fh]|wmf)"?\ *$/ REJECT attachment type not allowed |