You are here

Server error: '501 5.1.3 Bad recipient address syntax'

A user of my mail server recently had some recipients of a message returned. He received this message from my server.

The following recipient(s) cannot be reached:

       'redacted@civ.utoronto.ca' on 8/20/2014 10:35 AM
             Server error: '501 5.1.3 Bad recipient address syntax'

       'redacted@wlu.ca' on 8/20/2014 10:35 AM
Server error: '501 5.1.3 Bad recipient address syntax' 'redacted@uoguelph.ca' on 8/20/2014 10:35 AM
Server error: '501 5.1.3 Bad recipient address syntax' 'redacted@uoguelph.ca' on 8/20/2014 10:35 AM
Server error: '501 5.1.3 Bad recipient address syntax' 'redacted@eng.uwo.ca' on 8/20/2014 10:35 AM
Server error: '501 5.1.3 Bad recipient address syntax'

The other recipients were delivered successfully. On the server-side, Postfix logged:

Aug 20 14:35:17 darwin postfix/smtpd[63431]: warning: Illegal address syntax from 
or087.uwaterloo.ca[129.97.9.53] in RCPT command: <'redacted@uwo.ca'>
Aug 20 14:35:17 darwin postfix/smtpd[63431]: warning: Illegal address syntax from
or087.uwaterloo.ca[129.97.9.53] in RCPT command: <'
redacted@wlu.ca'>
Aug 20 14:35:17 darwin postfix/smtpd[63431]: warning: Illegal address syntax from
or087.uwaterloo.ca[129.97.9.53] in RCPT command: <'
redacted@eng.uwo.ca'>
Aug 20 14:35:17 darwin postfix/smtpd[63431]: warning: Illegal address syntax from
or087.uwaterloo.ca[129.97.9.53] in RCPT command: <'
redacted@grandriver.ca'>

The problem is that these particular addresses were literally enclosed by apostrophes. I don't know why the user's client (Outlook) misformatted these addresses. He confirmed that he did not copy them from another application or change anything at his end.

To fix the problem I configured Postfix to filter and rewrite the address when it is sending commands to other MTAs.

I added to main.cf:

# Strange filtering
smtpd_command_filter = pcre:/usr/local/etc/postfix/command_filter
and created the file command_filter:
# Fix malformed emails that are surrounded in single quotes.
/^RCPT\s+TO:\s*<'([^[:space:]]+)'>(.*)/     RCPT TO:<$1>$2

This fixed this oddity in which RCPT TO commands were not RFC 821-compliant.

Comments

Awesome! Thanks for this post, helped me fix my issue

Thank you, this worked perfectly!

Hint for others: on my Debian machine I had to install the package "postfix-pcre" to enable PCRE maps with Postfix.

Pages

Add new comment

Simple Copyright Policy: If you want to reproduce anything on this site, get my permission first.