Project

General

Profile

Feature #817

Updated by Daniel Curtis over 4 years ago

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:
<pre>
cat /var/log/maillog
</pre>
#*I found the following error message:
<pre>
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>
</pre>

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:
<pre>
vi /usr/local/etc/postfix/command_filter
</pre>
#* And add the following:
<pre>
# Regular expression to match addresses with spaces, then put quotes around it
/^RCPT\s+TO:<([^"[:space:]]+ .+)@([^[:space:]]+>.*)/ RCPT TO:<"$1"@$2
</pre>

* Now edit the main postfix config file:
<pre>
vi /usr/local/etc/postfix/main.cf
</pre>
#* And add the command_filter definition, along with smtpd_reject_unlisted_recipient:
<pre>
smtpd_command_filter = pcre:/usr/local/etc/postfix/command_filter

smtpd_reject_unlisted_recipient = no
</pre>

* Restart postfix:
<pre>
service postfix restart
</pre>

*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+.

h2. Resources

* http://www.postfix.org/postconf.5.html#smtpd_command_filter
* https://www.mail-archive.com/search?l=postfix-users@postfix.org&q=subject:%22Re%3A+Illegal+address+syntax%22&o=newest&f=1
* http://www.iredmail.org/forum/topic8668-iredmail-support-this-should-be-in-iredmail-by-default-etcpostfixmaincf.html
* http://yvanrodrigues.com/content/server-error-501-513-bad-recipient-address-syntax

Back