为什么 Google 会考虑请求 from my Django app通过 SMTP (smtp.gmail.com) 发送电子邮件不安全?阅读他们的 security standards不是很有帮助:
How more secure apps help protect your account When a third-party app meets our security standards, you can:
See what level of account access you’re giving the app before you connect your Google Account Let the app access only a relevant part of your Google Account, like your email or calendar Connect your Google Account to the app without exposing your password Disconnect your Google Account from the app at any time
从 Django 发送电子邮件时,这是一个非常常见的问题。有tutorials和 stackoverflow question/answers (第二个答案)通过更改您的谷歌帐户中的设置以允许安全性较低的应用程序来“解决”这个问题。在我从 Control Access to Less Secure Sites 读到这篇文章之前,我已经开始工作了,并且还可以接受它。 :
Because Google is beginning to shut off Google Account access to less secure apps, the enforcement option is no longer available. We recommend turning off less secure apps access now. You should start using alternatives to less secure apps.
As Google gradually moves away from allowing less secure apps to access Google Accounts, you’ll receive email notifications about changes that affect you.
当我尝试搜索“如何使用 Google 确保 Django 安全”或“为什么 Django 对 Google 来说是一个不安全的应用程序”时,我看到的结果反射(reflect)了更多相同的指导:只需拨动开关即可在您的 Google 帐户上允许不安全的应用程序。我想知道为什么 Django 被认为是不安全的,以便我可以将其配置为安全的。
编辑:我仍然没有验证这些步骤使 Django 成为“更安全的应用程序”。在那之前using an app password允许我关闭“允许安全性较低的应用程序”。实现起来非常简单。
最佳答案
并不是 Django 不安全,这可能是您使用 SMTP 发送电子邮件的方式。启用 TLS 是要做的第一件事,也是使用 Google 的 SMTP 服务的要求:
EMAIL_USE_TLS = True
EMAIL_PORT = 587
端口号取决于您使用的 SMTP 服务。 587 是标准,但也可能是其他标准。
接下来是设置SPF和 DKIM .
亚马逊SES (简单的电子邮件服务,不是免费的)使这几乎是透明的。
此外,您可以设置 DMARC它提供有关设置有效性的反馈。
Django 有一个 DKIM 包:https://pypi.org/project/django-dkim/帮助您手动设置。
此外,还有一个适用于 Django 2 和 Python 3 的 DMARC 包:https://pypi.org/project/django-dmarc2/ (我对原始包做了一些修复,使其与 Django 2+ 兼容)
应该在您的 DNS 上设置 SPF。
有了这个,应该使您的电子邮件安全。
关于python - 为什么 Django 根据谷歌是一个 'less secure' 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61433869/