Посмотрите на настройки smtpd_sender_restrictions
и smtpd_sender_login_maps
. Первая может предотвратить неправильное формирование from
адресов, а вторая может заставить адрес отправителя соответствовать имени входа в систему.
# Prevent malformed senders
smtpd_sender_restrictions =
reject_non_fqdn_sender # Ensure correct mail addresses
reject_unknown_sender_domain # Ensure sender address is from an existing domain
reject_authenticated_sender_login_mismatch # Check if the user is
# allowed to use this sender address
# Maps used to stop sender address forgeries.
smtpd_sender_login_maps = pcre:/etc/postfix/login_maps.pcre
Содержимое login_maps.pcre
может быть
# Use this regex if your users are local users, i.e. if the login name
# is just the username, not a full mail address.
# Note that literal dots have to be backslash escaped (`\.`) to avoid
# interpretation of these dots as regex wildcard.
/^([^@+]*)(\+[^@]*)?@example\.com$/ ${1}
# If one doesn't care about subaddresses, this could be simplified to
/^(.*)@example\.com/ ${1}
# This is appropriate if you have virtual users who login with their
# full mail address as their username. Local addresses won't work, though
/^(.*)$/ ${1}
Приведенный выше конфиг предполагает, что postfix был скомпилирован с поддержкой PCRE. На Ubuntu/Debian для этого необходимо установить пакет postfix-pcre
.
Обратите внимание, что это будет работать, только если никто, кроме аутентифицированных пользователей, не может отправлять почту. Если вы разрешите почту от неаутентифицированных пользователей, вышеописанный метод не поможет и приведет к неудаче. В этом случае обязательно прочитайте ответ Rui F Ribeiro.