Django send_mail函数中的email_from不起作用 [英] The email_from in Django send_mail function not working

查看:322
本文介绍了Django send_mail函数中的email_from不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上放置了一个联系表单,并且在我的settings.py

I put a contact form in my site, and I have this in my 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

这在我看来。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'])

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

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.

这种方式不起作用,或者我做错了什么?

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

我想得到发件人发送的电子邮件,所以y可以像在PHP中一样答复它。

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

谢谢。

推荐答案

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

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

每个用户iAn在类似帖子

per user iAn in a similar post


简短的答案-不能。

The short answer - you can't.

Google会重写通过SMTP服务发送的邮件中的发件人和回复收件人标头

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.

gmail的SMTP功能并非旨在作为开放服务或中继服务。如果发件人标头允许使用任何值,则将大大削弱Google在垃圾邮件服务方面的地位,因为将无法验证发件人的凭据。

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.

您需要考虑其他方法。您打算如何在完成脚本/应用程序/网站托管之后:几乎每个托管解决方案(共享/ vps /专用服务器)都将预先配置有电子邮件传输解决方案:* nix或IIS上的sendmail或postfix

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.

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

If you are intent on using gmail then you could:

设置专用的 myapp@gmail.com;帐户
如果您拥有要发送的域,请为域使用免费的gmail,并设置 myapp@mydomain.com帐户。

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.

这篇关于Django send_mail函数中的email_from不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆