Postfix:仅接收来自特定域的电子邮件?

Postfix:仅接收来自特定域的电子邮件?

如何设置 Postfix 以使其仅接收来自特定域的电子邮件?

我的服务器上有一个特定的电子邮件帐户,我只想让它接收从 txt.att.net、text.wireless.alltel.com 和 mms.alltel.net 转发的电子邮件。转发到此帐户的任何其他电子邮件都应退回给发件人。

答案1

这取决于你想如何限制它。我不确定你所说的是邮件中继还是发送地址。

发送地址

您可以在适当的 smtpd_*_restrictions 中使用 check_sender_access 指令。通常最佳做法是在收件人限制内应用所有发件人、主机检查等(即在客户端发送“RCPT To:”之后)

例如,仅允许来自发件人@gmail.com 和@hotmail.com 的邮件...

将 smtpd_recipient_restrictions 设置为以下内容:

smtpd_recipient_restrictions =
    check_sender_access hash:/etc/postfix/access,
    reject

现在 /etc/postfix/access 应该是这样的形式:

gmail.com OK
hotmail.com OK

使用 postmap hash:/etc/postfix/access 创建哈希表。

中继主机名或 IP

smtpd_recipient_restrictions =
    check_client_access hash:/etc/postfix/client_access,
    reject

client_access的格式类似:

host.name.of.system.com  OK
ip.addr.of.system        OK

阅读你的日志

以下是我的 mail.log 中示例消息的完整摘录。我挑选了一条消息并获得了队列 ID - 31AF4761F3。它将出现在邮件标题以及您的邮件日志文件中。

$ grep 31AF4761F3 /var/log/mail.log
Sep  4 09:30:38 cutoffs postfix/smtpd[7912]: 31AF4761F3: client=russian-caravan.cloud9.net[w.x.y.z]
Sep  4 09:30:38 cutoffs postfix/cleanup[7915]: 31AF4761F3: message-id=<007B93C54F154113B36026A22D5E0106@gaby>
Sep  4 09:30:38 cutoffs postfix/qmgr[19172]: 31AF4761F3: from=<[email protected]>, size=4225, nrcpt=1 (queue active)
Sep  4 09:30:39 cutoffs postfix/pipe[7916]: 31AF4761F3: to=<XXXX@XXXX>, relay=spamassassin, delay=1.4, delays=0.19/0.01/0/1.3, dsn=2.0.0, status=sent (delivered via spamassassin service)
Sep  4 09:30:39 cutoffs postfix/qmgr[19172]: 31AF4761F3: removed

您可以在第一行看到,client=russian-caravan.cloud9.net(这是为 postfix 邮件列表发送邮件的邮件服务器),IP 地址在括号中。您可以在访问文件中使用主机名或 IP,但请记住,如果他们有多个邮件中继或曾经更改过邮件中继,您需要弄清楚这一点。

答案2

phil 的回答很好,除了一个细节。不要在 /etc/postfix/access 或 /etc/postfix/client_access 的 RHS 上使用“OK”。这会使您的邮件服务器成为部分开放中继,供任何声称从 @gmail.com 或 @hotmail.com (access) 发送邮件的人或为 client_access 中允许的特定主机发送邮件。这不仅允许他们向您系统上的特定用户发送邮件,还允许他们通过您的系统将邮件中继给任何系统上的任何用户。

而是使用“permit_auth_destination”。这允许他们发送到您的本地域,或者您配置为中继的任何域,但不能发送到任何任意域。

例如

在/etc/postfix/访问:

gmail.com permit_auth_destination
hotmail.com permit_auth_destination

在/etc/postfix/client_access中:

主机.系统名称.com permit_auth_destination
系统允许认证目的地的 IP 地址

即使所有其他配置都已完美配置,在后缀访问规则中使用“OK”也是一个坏习惯。有时你确实需要它,但默认情况下你的习惯应该是使用“permit_auth_destination”。

答案3

根据此链接:[http://www.postfix.org/RESTRICTION_CLASS_README.html#internal][2]

我的配置:

/etc/postfix/main.cf

 smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/protected_destinations,permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
 smtpd_restriction_classes = insiders_only
 insiders_only = check_sender_access hash:/etc/postfix/insiders, reject

/etc/postfix/内部人员

 mydomain.com            OK
 otherdomain.com         OK
 [email protected]       OK

在/etc/postfix/protected_destinations

restricted_email@      insiders_only

然后

 postmap /etc/postfix/insiders
 postmap /etc/postfix/protected_destinations
 /etc/init.d/postfix restart

此设置仅允许来自 /etc/postfix/insiders 对象的传入电子邮件,并且仅影响文件 protected_destinations 中保存的地址,而不影响全局系统,因此所有其他用户都可以像往常一样收到传入邮件。请注意,它可以是域和/或电子邮件地址。

restricted_email@ insiders_only 行涵盖服务器中的所有域。我的服务器上只保留本地用户,我需要在 restricted_email 末尾添加“@”,以便与所有 restricted_email@domains 一起使用,这正是我想要的。

相关内容