您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Django send_mail函数中的email_from不起作用

5b51 2022/1/14 8:23:20 python 字数 2993 阅读 589 来源 www.jb51.cc/python

我在我的网站上放了一个联系表单,我在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中

概述

# 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中一样.

谢谢.

每个用户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.

总结

以上是编程之家为你收集整理的Django send_mail函数中的email_from不起作用全部内容,希望文章能够帮你解决Django send_mail函数中的email_from不起作用所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶