加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Django send_mail函数中的email_from不起作用

发布时间:2020-12-16 23:39:20 所属栏目:Python 来源:网络整理
导读:我在我的网站上放了一个联系表单,我在settings.py中有这个 # Email settingsEMAIL_USE_TLS = TrueEMAIL_HOST = 'smtp.gmail.com'EMAIL_HOST_USER = 'myemail@gmail.com'EMAIL_HOST_PASSWORD = '****'EMAIL_PORT = 587 这在我的views.py中 name = form.cleane
我在我的网站上放了一个联系表单,我在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 + 'rn' + email + 'rnrn' + 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读