Django send_mail email_from function not working

I have posted the contact form on my website, and I have it in my settings.

# Email settings EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = ' myemail@gmail.com ' EMAIL_HOST_PASSWORD = '****' EMAIL_PORT = 587 

And this is in my views.py

 name = form.cleaned_data['name'] email = form.cleaned_data['email'] message = form.cleaned_data['message'] subject = 'Email from ' + name content = name + '\r\n' + email + '\r\n\r\n' + message send_mail(subject, content, email, [' me@myemail.com ']) 

Everything works correctly, I receive an email with all the information, but the email comes from myemail@gmail.com , although the from_email parameter has an email var with an email sender.

Does this not work, or am I doing something wrong?

I wanted to receive an email from the sender, so that y can simply reply to it, as in PHP.

Thanks.

+6
source share
1 answer

Gmail will not let you spoof where the email came from.

for iAn user in a similar message

The short answer is you cannot.

Google overwrites the From and Reply-To headers in messages sent through the SMTP service to the values ​​that apply to your gmail account.

The gmail SMTP function is not intended for the open or relay service. If this allowed any values ​​for the From header, it would significantly reduce Google’s reputation for spam services, as it would not be possible to verify the sender’s credentials.

You need to consider alternatives. How do you plan to host your script / application / website upon completion: almost all hosting solutions (shared / vps / dedicated server) will be preconfigured using an email solution: whether it is sendmail or postfix on * nix, or IIS on Windows .

If you intend to use gmail, you can:

Setting up a dedicated account " myapp@gmail.com " If you have a domain from which you are allegedly sending, use free gmail for domains and set up an account myapp@mydomain.com .

+8
source

Source: https://habr.com/ru/post/893424/