Feature #817

Filter Recipient Email Addresses Containing Spaces on Postfix

Added by Daniel Curtis about 6 years ago. Updated about 6 years ago.

Mail Server
Start date:
Due date:
% Done:


Estimated time:
0.50 h
Spent time:


I recently had a user having emails stuck in their email client's outbox. After doing some initial troubleshooting I found that one of the recipient addresses had a space in it, causing the email to be malformed an undeliverable.

  • Looking around in the maillog:
    cat /var/log/maillog

    #*I found the following error message:
    Jun  6 16:51:59 mail postfix/smtpd[35766]: 834C4A3FAA: reject: RCPT from unknown[]: 450 4.7.1 <SOME>: Recipient address rejected: Access denied; from=<> to=<SOME> proto=ESMTP helo=<>

To work around this problem, I used the command_filter feature provided by postfix (version 2.7+) and created a regular expression to put quotations around any email addresses matching with a space.

  • Create the command_filter file:
    vi /usr/local/etc/postfix/command_filter
    • And add the following:
      # Regular expression to match addresses with spaces, then put quotes around it
      /^RCPT\s+TO:<([^"[:space:]]+ .+)@([^[:space:]]+>.*)/  RCPT TO:<"$1"@$2
  • Now edit the main postfix config file:
    vi /usr/local/etc/postfix/
    • And add the command_filter definition, along with smtpd_reject_unlisted_recipient:
      smtpd_command_filter = pcre:/usr/local/etc/postfix/command_filter
      smtpd_reject_unlisted_recipient = no
  • Restart postfix:
    service postfix restart

NOTE: This does not magically correct wrong email address. Incorrect email addresses will either bounce back to the sender or be caught by a catch-all email box.



Updated by Daniel Curtis about 6 years ago

  • Subject changed from Filter Email Addresses With Spaces on Postfix to Filter Recipient Email Addresses Containing Spaces on Postfix
  • Description updated (diff)
  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Updated by Daniel Curtis about 6 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF