Django send_mail函数中的email_from不起作用

时间:2021-08-15 18:15:04

I put a contact form in my site, and I have this in my settings.py

我在我的网站上放了一个联系表单,我在settings.py中有这个

# 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 in my views.py

这在我的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'])

It all works correctly, i get the email with all the information, but, the email comes from myemail@gmail.com even though the from_email parameter has the email var with the senders email.

一切正常,我收到包含所有信息的电子邮件,但是,电子邮件来自myemail@gmail.com,即使from_email参数包含发件人电子邮件的电子邮件var。

It doesn't work that way or i'm doing something wrong?

它不起作用或我做错了什么?

I wanted to get the email from the sender, so y can just reply to it, like i do in PHP.

我想从发件人那里收到邮件,所以你可以回复它,就像我在PHP中一样。

Thank you.

1 个解决方案

#1


8  

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

Gmail不会让您欺骗电子邮件的来源。

per user iAn in a similar post

每个用户iAn在类似的帖子中

The short answer - you can't.

简短的回答 - 你不能。

Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.

Google会将您通过其SMTP服务发送的邮件中的“发件人”和“回复”标题重写为与您的Gmail帐户相关的值。

The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.

Gmail的SMTP功能不是开放或中继服务。如果它允许From标头的任何值,它将大大淡化Google在垃圾邮件服务方面的地位,因为无法验证发件人的凭据。

You need to consider alternatives. How are you planning to host your script/application/website when it's finished: virtually every hosting solutions (shared/vps/dedicated server) will come pre-configured with an email transfer solution: be it sendmail or postfix on *nix, or IIS on Windows.

你需要考虑替代方案。你打算如何在完成后托管你的脚本/应用程序/网站:几乎每个托管解决方案(共享/ vps /专用服务器)都将预先配置一个电子邮件传输解决方案:无论是在* nix上的sendmail还是postfix,还是IIS在Windows上。

If you are intent on using gmail then you could:

如果您打算使用gmail,那么您可以:

Setup a dedicated "myapp@gmail.com" account If you own the domain you are supposedly sending from, use the free gmail for domains, and setup a "myapp@mydomain.com" account.

设置专用的“myapp@gmail.com”帐户如果您拥有您应该发送的域名,请使用域名的免费Gmail,并设置“myapp@mydomain.com”帐户。

#1


8  

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

Gmail不会让您欺骗电子邮件的来源。

per user iAn in a similar post

每个用户iAn在类似的帖子中

The short answer - you can't.

简短的回答 - 你不能。

Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.

Google会将您通过其SMTP服务发送的邮件中的“发件人”和“回复”标题重写为与您的Gmail帐户相关的值。

The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.

Gmail的SMTP功能不是开放或中继服务。如果它允许From标头的任何值,它将大大淡化Google在垃圾邮件服务方面的地位,因为无法验证发件人的凭据。

You need to consider alternatives. How are you planning to host your script/application/website when it's finished: virtually every hosting solutions (shared/vps/dedicated server) will come pre-configured with an email transfer solution: be it sendmail or postfix on *nix, or IIS on Windows.

你需要考虑替代方案。你打算如何在完成后托管你的脚本/应用程序/网站:几乎每个托管解决方案(共享/ vps /专用服务器)都将预先配置一个电子邮件传输解决方案:无论是在* nix上的sendmail还是postfix,还是IIS在Windows上。

If you are intent on using gmail then you could:

如果您打算使用gmail,那么您可以:

Setup a dedicated "myapp@gmail.com" account If you own the domain you are supposedly sending from, use the free gmail for domains, and setup a "myapp@mydomain.com" account.

设置专用的“myapp@gmail.com”帐户如果您拥有您应该发送的域名,请使用域名的免费Gmail,并设置“myapp@mydomain.com”帐户。