Configure postfix to send email only from authenticated and receive from anywhere

configurationemailpostfix

I`m having problem configuring postfix to receive emails from any domain but block senders for only authenticated users in localhost

My main.cf is like :

mydomain = domainname
myhostname = mail.$mydomain
myorigin = /etc/mailname
smtpd_banner = $myhostname
biff = no
append_dot_mydomain = no
readme_directory = no
mydestination =
relayhost =
mynetworks = 127.0.0.0/8
mynetworks_style = host
mailbox_size_limit = 0
virtual_mailbox_limit = 0
recipient_delimiter = +
inet_interfaces = all
message_size_limit = 0

smtpd_helo_required = yes
smtpd_delay_reject = yes
disable_vrfy_command = yes
smtpd_sender_restrictions =     permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination

In this case I can receive from any domain email but can send from localhost without authenticate.

If I change this line to :

smtpd_sender_restrictions = permit_sasl_authenticated,reject_unauth_destination

then I can't receive email from other domains with error 554 5.7.1 <balbal@gmail.com>: Sender address rejected: Access denied, and can send from localhost if only authenticated.

How can I configure postfix to receive email from any domain and allow send only if authenticated including localhost?

Best Answer

Just going to quote from my working Postfix configuration:

smtpd_sender_restrictions =
        permit_sasl_authenticated,
        permit_mynetworks,
        reject_unauthenticated_sender_login_mismatch,
        permit

Note that this allows authenticated users to send mail with any FROM address they wish. If you want users to be able to send mail only with the email address they login with, use reject_sender_login_mismatch instead.

Also note that your configuration is incomplete. You will also need several other directives to complete the configuration, primarily smtpd_recipient_restrictions.