简体   繁体   English

在 ZEF0F93C83E374876A61DA0D4D16F36 中使用 gmail smtp 发送 email 时出错

[英]Error in sending email using gmail smtp in Django app

I set up everything as the Django documentation but when I test sending an email.It works but When I check my inbox I find out that I sent and revived from to the same email address.我将所有内容设置为 Django 文档,但是当我测试发送 email 时。它可以工作,但是当我检查我的收件箱时,我发现我发送并恢复到同一个 Z0C83F57C786A0B4A39EFAB23731C7 地址。

Here is the settings.py这是settings.py

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = "myemail@gmail.com"
EMAIL_HOST_PASSWORD = "mypassword" 

And the views.py和views.py

...
send_mail( 'subject', 'message', 'user@gmail.com', ['myemail@gmail.com',], fail_silently=False, )
...

But I received an email from myemail@gmail.com to me(myemail@gmail.com).但是我从 myemail@gmail.com 收到了 email 给我(myemail@gmail.com)。

Im not sure if you did this already but if youre using gmail then you will need to do the following.我不确定您是否已经这样做了,但是如果您使用的是 gmail,那么您将需要执行以下操作。

Sign in to your Google Admin console (Sign in using an administrator account)
Click Security > Less secure apps.
Select Allow users to manage their access to less secure apps.
Click Save.25

Also you should use environment variables for the email address if you are live already eg:此外,如果您已经使用 email 地址,您还应该使用环境变量,例如:

EMAIL_HOST_USER = os.environ.get('MY_EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('MY_EMAIL_PASS')

If its all working and you are just getting the mail to the wrong address can you send on the document you followed?如果一切正常并且您只是将邮件发送到错误的地址,您可以发送您关注的文档吗?

In terms of you settings.py that looks fine to me.就您而言,settings.py 对我来说看起来不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM