Feature #817
Filter Recipient Email Addresses Containing Spaces on Postfix
Status:
Closed
Priority:
Normal
Assignee:
Category:
Mail Server
Target version:
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
- And add the following:
- 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
- And add the command_filter definition, along with smtpd_reject_unlisted_recipient:
- 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¶
- 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
Updated by Daniel Curtis over 8 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