Project

General

Profile

Feature #817

Filter Recipient Email Addresses Containing Spaces on Postfix

Added by Daniel Curtis almost 8 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Mail Server
Start date:
06/06/2016
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

Description

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[192.168.1.147]: 450 4.7.1 <SOME otheruser@example.com>: Recipient address rejected: Access denied; from=<user@example.com> to=<SOME otheruser@example.com> proto=ESMTP helo=<android-5215693721918913.example.com>
    

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/main.cf
    
    • 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.

Resources

Also available in: Atom PDF