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']
Alasdair
source share