I'm sending my emails using Postfix, and I've got a considerable list of emails to send newsletters to. So I prefer to pack my SMTP requests into one by setting one of emails as To
and a bunch more as Bcc
(in PHP).
My problem is that if one of the emails is invalid, Postfix rejects the whole request prompting the following error:
5.1.1 : Recipient address rejected: User unknown in local recipient table
It would be great if I could configure Postfix in a way so it dumps the invalid one but sends the rest. I know I can validate the addresses myself before using them in an email but I prefer it if it is done by Postfix.
[UPDATE]
Here's the maillog's content:
Nov 18 16:20:28 mail postfix/smtpd[12922]: 14A5FB812E1: client=localhost[127.0.0.1]
Nov 18 16:20:28 mail postfix/smtpd[12922]: 14A5FB812E1: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 <mehran_hotmail.com>: Recipient address rejected: User unknown in local recipient table; from=<mehran@localhost> to=<mehran_hotmail.com> proto=ESMTP helo=<localhost>
This error is generated while I tried to send an email with mehran@hotmail.com
as the main recipient and mehran_hotmail.com
as the Bcc
.
[UPDATE]
Here's the complete log associated with the request:
Nov 19 09:47:01 mail postfix/smtpd[20947]: connect from localhost[127.0.0.1]
Nov 19 09:47:01 mail postfix/smtpd[20947]: EC281B81BCE: client=localhost[127.0.0.1]
Nov 19 09:47:01 mail postfix/smtpd[20947]: warning: Illegal address syntax from localhost[127.0.0.1] in RCPT command: <mehran@?????.com>
Nov 19 09:47:01 mail postfix/smtpd[20947]: disconnect from localhost[127.0.0.1]
This is a new scenario (leading to the same problem) in which I used a correct email address (both To
and Bcc
hold correct email addresses but not the same address) but this time the email address is rejected because Postfix does not recognize it. I used non-ASCII characters as for the domain name (mehran@مهران.com). I don't care whether Postfix supports non-ASCII addresses or not, it's just that when it rejects one address, the whole request is rejected!! And no email is sent to mehran@hotmail.com (which is named in To
)!
Now the returned error message to my code (PHP made MUA) is:
5.1.3 Bad recipient address syntax
As for my PHP code which interacts with SMTP
server:
$mail = new \Zend_Mail('utf-8');
$mail->setMessageId($mail->createMessageId());
foreach ($array_to as $to) {
$mail->addTo($to['email'], $to['name']);
}
foreach ($array_cc as $to) {
$mail->addCc($to['email'], $to['name']);
}
foreach ($array_bcc as $to) {
$mail->addBcc($to['email'], $to['name']);
}
$mail->setSubject($subject);
$mail->setBodyHtml($body);
$mail->setFrom($current_user_email, $current_user_name);
$mail->setDate(new \Zend_Date());
$smtp = createSmtpConnection();
$smtp->send($mail);
As you can see I used Zend Framework (v1) and my code is rather simple. The $array_*
variables are simple arrays holding the email addresses. In my test scenario there are only two email addresses, one for To
and one for Bcc
.
Best Answer
TLDR: Your case is abnormal behavior mail client in proper SMTP transaction. Maybe something wrong in your PHP code. See this thread on postfix mailing list. A quote from Postfix author in that thread
How is SMTP rejection works
First, we will take the tour of SMTP transaction. Below is how SMTP works in low level. You can always try it via telnet/netcat.
Case 1 This is the transaction when there is a single recipient.
So, SMTP is chatty protocol, every time the client issuing command (HELO/MAIL/RCPT/DATA/QUIT), the server should answer it before the transaction continue. In this case all the answer has code 250, or in human languange I accepted it.
Case 2 SMTP transaction for multiple recipients
In this example there are three recipient. We are using multiple RCPT command in single transaction. RCPT command is special command. This command can be repeated multiple times for a given e-mail message in order to deliver a single e-mail message to multiple recipients.
Case 3 If some recipients rejected (but not all), the transaction was continued. Here the sample transaction.
Why the server still accept the email? Because there are two valid recipients beside one invalid one.
Disclaimer: Above resources taken from here.
(unsuccessful) Attempt to Reproduce the Problem
OK, I have tried to reproduce your problem in my box. This is my PHP code with library PHPMailer. (I don't familiar with zend Framework)
Because
SMTPDebug
has enabled, the output contains full SMTP transaction. This output similar with above example.and the maillog entry
Well looks like in my box, postfix and PHPMailer behave in normal circumstances. You can use this to compare with maillog in your box :)