如何发送报告邮件,例如 Google

How to send report mail like Google

我在本地有一个使用 Django 框架 运行 的网站,我希望网站自动发送电子邮件到电子邮件地址,但我在配置 EMAIL_HOST、EMAIL_HOST_USER 时遇到问题, EMAIL_HOST_PASSWORD 和 EMAIL_PORT 在 settings.py

这是settings.py我配置的:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST = 'localhost'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 25

如何解决才能发送电子邮件?

您的项目在本地主机上运行,​​但您的邮件服务器在 google

上运行

试试这个

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD

您将需要设置 Gmail,例如使用应用程序密码。 请参阅 google 指南 here and for app passwords here

If you connect using SSL or TLS, you can send mail to anyone with smtp.gmail.com.

Note: Before you start the configuration, we recommend you set up App passwords for the the desired account. Learn more at Sign in using App Passwords and Manage a user's security settings.

Connect to smtp.gmail.com on port 465, if you’re using SSL. (Connect on port 587 if you’re using TLS.) Sign in with a Google username and password for authentication to connect with SSL or TLS. Ensure that the username you use has cleared the CAPTCHA word verification test that appears when you first sign in.

但是,如果您使用的是 gmail,那么您应该查看 gmail api,因为这样您就可以处理入站邮件,并且可以使用标签等来管理邮件,一旦您收到邮件,它最终会运行良好了解 oAuth 等。我知道你没有问过这个,但我个人觉得它很有用。