Error: SMTPRecipientsRefused 553, '5.7.1 #while while working in contact form in django

im trying to create a contact form in django 1.3, python 2.6.

What is the cause of the following error?

Mistake:

SMTPRecipientsRefused at /contact/ {'test@test.megiteam.pl': (553, '5.7.1 <randomacc@hotmail.com>: Sender address rejected: not owned by user test@test.megiteam.pl')} 

my settings.py:

 EMAIL_HOST = 'test.megiteam.pl' EMAIL_HOST_USER = 'test@test.megiteam.pl' EMAIL_HOST_PASSWORD = '###' DEFAULT_FROM_EMAIL = 'test@test.megiteam.pl' SERVER_EMAIL = 'test@test.megiteam.pl' EMAIL_USE_TLS = True 

edit: If any1 else was the next djangobook, this is the part calling it:

  send_mail( request.POST['subject'], request.POST['message'], request.POST.get('email', 'noreply@example.com'), #get rid of 'email' ['siteowner@example.com'], 
+8
python django smtp sendmail
source share
1 answer

The explanation is given in the error message. Your mail host rejects the email address because of the sender address randomacc@hotmail.com that you selected from the contact form.

Instead, you should use your own email address as the sender address. You can use the reply_to parameter reply_to that the answers go to your user.

 email = EmailMessage( 'Subject', 'Body goes here', 'test@test.megiteam.pl', ['to@example.com',], reply_to='randomacc@hotmail.com', ) email.send() 

There is no reply_to argument in Django 1.7 and earlier, but you can manually set the Reply-To header:

 email = EmailMessage( 'Subject', 'Body goes here', 'test@test.megiteam.pl', ['to@example.com',], headers = {'Reply-To': 'randomacc@hotmail.com'}, ) email.send() 

Edit:

In the comments, you asked how to include the sender address in the body of the message. message and from_email are just strings, so you can combine them, but you want them before sending an email.

Please note that you should not receive the from_email argument from your from_email . You know that from_address should be test@test.megiteam.pl , so use this or maybe import DEFAULT_FROM_EMAIL from your settings.

Please note: if you create a message using EmailMessage , as in my example above, and set the response to the header, then your mail client should do the right thing when you click the reply button. The example below uses send_mail so that it looks like the code you linked to .

 from django.conf import settings ... if form.is_valid(): cd = form.cleaned_data message = cd['message'] # construct the message body from the form cleaned data body = """\ from: %s message: %s""" % (cd['email'], cd['message']) send_mail( cd['subject'], body, settings.DEFAULT_FROM_EMAIL, # use your email address, not the one from the form ['test@test.megiteam.pl'], ) 
+10
source share

All Articles