Django send_mail函数中的email_from不起作用

前端之家收集整理的这篇文章主要介绍了Django send_mail函数中的email_from不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的网站上放了一个联系表单,我在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

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

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

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

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

谢谢.

解决方法

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

每个用户iAn在similar post

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.

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.

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.

If you are intent on using gmail then you could:

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.

猜你在找的Python相关文章