0

I made a "Contact Us" form in Django, and the Django part of it seems to be working. But sending of the email it generates fails with

SMTPRecipientsRefused at /contact/

{'[email protected]': (553, b'5.7.1 <[email protected]>: Sender address rejected: not owned by user [email protected]')}

If I change the Django settings to send the email to the console, it displays the email in the console properly. But when I try sending the email to my mail server, Postfix seems to be blocking it. from what I've read this is meant to prevent someone from sending out emails from an email address they do not control, but in this case the email is coming through a "Contact Us" form I built. If I input the same email address in the form as the recipient, namely [email protected], an email does arrive at the other end. But if I put in any other email address as the mail_from, it throws this error.

I've read through the Postfix docs but they just confused me, can anyone help?

New contributor
LeonTheGreat is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

2

The message clearly says Sender address rejected. So not a recipient was actually refused, but a sender. The (arguably confusing) SMTPRecipientsRefused exception fired probably because the server has smtpd_delay_reject enabled, so it will proceed with the protocol and only report rejection after RCPT TO command, even if it decided to reject the transaction as early as after the MAIL FROM command.

The not owned by user ... is produced by the reject_sender_login_mismatch (or reject_authenticated_sender_login_mismatch) item somewhere in your Postfix configuration, probably in smtpd_sender_restrictions where it normally goes, but also possible in smtpd_recipient_restrictions or smtpd_relay_restrictions. It is a good thing as it considerably enhances the server security against spamming.

So, your server seems to have SMTP authentication set up and also it has some mapping from envelope sender addresses to SMTP logins. Certain sender email addresses may only be used by certain users. Your application seems to be authenticating as the user [email protected], and that user is not allowed to use [email protected] as a sender address.

You have to be careful here, because there are different things in the email technology which you can refer to as a "sender address". In this case we are talking about "envelope sender address" which is reported to the server during SMTP session in the MAIL FROM command. Don't confuse it with the "from" address that appears within the message data, in the From MIME header.

Your options are:

  • ask the mail server administrator to allow [email protected] to use [email protected] as the envelope sender address;
  • ask administrator which address this user is allowed to use and then reconfigure your application to use allowed address during the SMTP session.

Probably, the address [email protected] is already allowed for the user [email protected]. Configure it to be used in the SMTP session. If you want to receive replies to some other address, add that address into the message as Reply-To MIME header. Also you may want to use other address in the message's From MIME header. Again, don't confuse "envelope sender address" and From MIME header. You may set up MIME headers relatively freely, but envelope sender address must be set in accordance with the server configuration. How and where to set this up depends on your SMTP framework; we can't help you with that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .