Chr*_*her 16 linux postfix smtp-auth
我已经使用 SMTP AUTH(端口 587 上的 STARTTLS)设置了 Postfix 服务器。我所有的用户都在域“example.org”中。我想强制发件人地址为“logged-in-user@example.org”。
我了解到这可以通过 main.cf 选项来实现
smtpd_sender_restrictions = reject_sender_login_mismatch, ...
smtpd_sender_login_maps = hash:/etc/postfix/smtpd_sender_login_maps
Run Code Online (Sandbox Code Playgroud)
使用 login_maps 文件,例如:
a@example.org a
b@example.org b
c@example.org c
...
Run Code Online (Sandbox Code Playgroud)
(另请参阅使用 SMPT AUTH 阻止发件人地址欺骗),但这意味着每次有新用户时我都必须编辑 login_maps 文件。我不需要这么灵活的映射:它应该始终是“logged-in-user@example.org”。有没有更简单的选择?
mai*_*ilq 14
首先,通过输入命令postconf -m并在其中查找一行来检查您安装的 Postfix 是否支持 pcre pcre。确认您拥有 pcre 支持后,您可以执行以下操作:
/etc/postfix/login_maps.pcre:
/^(.*)@example\.org$/ ${1}
Run Code Online (Sandbox Code Playgroud)
在main.cf:
smtpd_sender_login_maps = pcre:/etc/postfix/login_maps.pcre
Run Code Online (Sandbox Code Playgroud)
这应该可以正常工作。
另一个答案中提到的正则表达式匹配电子邮件地址的用户部分(登录用户@example.org)。这是一些额外的信息。
要将完整的电子邮件地址用作用户名,请使用以下正则表达式(例如在 中/etc/postfix/login_map):
/^(.*)$/ ${1}
Run Code Online (Sandbox Code Playgroud)
这意味着您的用户名始终是您的完整电子邮件地址(login-user@example.org) - 不允许从该地址发送其他现有用户名 - 并且您不必每次更新额外的 Postfix 配置文件添加用户。
这可能用于配置了多个域的服务器。用户john.doe@example.com只能从该地址发送,而不能从john.doe@example.org(不同的用户和电子邮件,不同的人)发送。在这种情况下,用户名john.doe会不明确。
此外,根据您的配置,必须指向此文件的 smtpd_sender_login_maps 设置可能位于 master.cf(而不是 main.cf)中。官方Dovecot 文档有以下示例(如果您使用的是 SASL/提交):
submission inet n - n - - smtpd
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_sasl_security_options=noanonymous
-o smtpd_sasl_local_domain=$myhostname
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o smtpd_sender_login_maps=hash:/etc/postfix/virtual
-o smtpd_sender_restrictions=reject_sender_login_mismatch
-o smtpd_recipient_restrictions=reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject
Run Code Online (Sandbox Code Playgroud)
在此示例中,应调整设置以指向正确的文件并使用正则表达式或(更好的)pcre 作为类型。特别是如果一个名为“virtual”的文件已经用于其他目的(例如virtual_alias_maps,如官方 Postfix 示例所示),则应使用另一个文件进行登录映射。
从:
smtpd_sender_login_maps=hash:/etc/postfix/virtual
Run Code Online (Sandbox Code Playgroud)
到:
smtpd_sender_login_maps=pcre:/etc/postfix/login_map
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16221 次 |
| 最近记录: |