Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have set up a Postfix server with SMTP AUTH (STARTTLS on port 587). All my users are in the domain "". I want to enforce the sender address to be "".

I learned that this can be achieved with the options

smtpd_sender_restrictions = reject_sender_login_mismatch, ...
smtpd_sender_login_maps = hash:/etc/postfix/smtpd_sender_login_maps

with a login_maps file like: a b c

(see also Block sender address spoofing with SMPT AUTH), but this would mean I'll have to edit the login_maps file every time I have a new user. I don't need such a flexible mapping: It should always be "". Is there an easier option?

share|improve this question
up vote 8 down vote accepted

You need pcre regex compiled in Postfix. Or the distribution already includes pcre. postconf -m should show a line with pcre in it. And then you can do:


/^(.*)$/   ${1}


smtpd_sender_login_maps = pcre:/etc/postfix/login_maps.pcre

Should work fine as expected. If not let me know so that I edit it when needed.

share|improve this answer
This is perfect. Exactly what I was looking for! – Chris Lercher Oct 4 '11 at 18:56
For Ubuntu users, you can get postfix pcre with sudo apt-get install postfix-pcre. Maybe this was obvious to most. – NeilMonday Mar 1 at 2:48

The regex mentioned in the other answer matches the user part of the email address ( Here is some additional information.

To use the full email address as username, use the following regex (for example in /etc/postfix/login_map):

/^(.*)$/   ${1}

This means that your username is always your full email address ( - no other existing username is allowed to send from that address - and you don't have to update an additional Postfix config file everytime you add a user.

This might be used on a server that has multiple domains configured. User is only allowed to send from that address but not from (different user and email, different person). The username john.doe would be ambiguous in this case.

Also, depending on your configuration, the smtpd_sender_login_maps setting, which has to point to this file, may be in the (instead of The official Dovecot documentation has the following example (if you're using SASL/submission):

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

In this example, the setting should be adjusted to point to the right file and use regex or (better) pcre as type. Especially if a file called "virtual" is already used for another purpose (for example for virtual_alias_maps, as shown in an official Postfix example), another file should be used for the login mapping.




share|improve this answer

Can you use combination of regexp on the header as shown here: Then you can combine with regexp like [*] to ensure only sender from

share|improve this answer
Let's assume, I can use "regexp:" here (?) How can I specify the regexp such, that user "a" can send as "" but not as ""? – Chris Lercher Oct 4 '11 at 14:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.