I am trying to configure a Postfix server to:

  • Deliver mail from local users to both other local users and remote addresses; and
  • Accept incoming mail only for some (explicitly listed) addresses of my domain (regardless of what the local users are).

The hostname of the machine is mydomain.con and I have currently configured postfix as follows:

  • myhostname = localhost
  • mydestination = localhost (this prevents mails for localuser@mydomain.com to be accepted)
  • virtual_alias_domains = mydomain.com
  • virtual_alias_maps = hash:/etc/postfix/virtual, where /etc/postfix/virtual maps email addresses from mydomain.com to local users, e.g.:
john.smith@mydomain.com localuser@localhost

This setup works correctly for incoming mail sent to john.smith@mydomain.com (it is delivered to user localuser). However, it doesn't allow local users to send mail to other local users. For example, an email sent to user alice (e.g., using mail alice) is sent to alice@mydomain.com, which is then matched (unsuccessfully) against the virtual alias file, and the delivery ultimately fails.

Can somebody advise me? Do I need to change the hostname of the machine to a private one and set myhostname accordingly? If so, how can I prevent outside clients from delivering mail to localuser@myhostname?

On somewhat related note: what part of the Postfix configuration (if any) is currently preventing it from accepting mail for localuser@localhost from a foreign SMTP client? (notice that rejecting mail addressed to localuser@localhost is the desired behavior)

Thank you!

  • mail client uses dns mx record and localhost is not a domain, local mail users are internal to the mail mailserver, when you write an email from user1@domain.com to user2@domain.com the delivery is locally, you could try checking the postfix logs
    – c4f4t0r
    Jul 20 '20 at 7:06
  • @c4f4t0r, I know about MX records and clearly no legitimate mail client would attempt to deliver mail for localuser@localhost to my server. Yet, nothing prevents a malicious client from directly connecting to the server's address on port 25 and try to deliver mail addressed to localuser@localhost. I'm just asking what part of the default postfix configuration (if any) is responsible for rejecting such messages.
    – Steven
    Jul 21 '20 at 17:05
  • you are looking for reject_unauth_destination
    – c4f4t0r
    Jul 21 '20 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.