如何为 SMTP 配置 Django 和 G Suite
How to configure Django and G Suite for SMTP
当用户在我的网站上注册时,会向用户发送一封电子邮件以确认 his/her 电子邮件。
它适用于此设置:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemail@gmail.com'
EMAIL_HOST_PASSWORD = 'abcdefghiklmnopq'
EMAIL_PORT = 587
现在我想切换到 noreply@mydomain.com。
我在 G Suite 上创建了一个帐户并进行了以下配置:
Comprehensive mail storage (Locally applied)
Ensure that a copy of all
sent and received mail is stored in associated users' mailboxes: ON
SMTP relay service (Locally applied)
ms_mail
Allowed senders: Only
addresses in my domains
Only accept mail from the specified IP
addresses: No
Require SMTP Authentication: Yes
Require TLS encryption:
Yes
Less secure apps (Locally applied)
Allow Users to manage their access to less secure apps
Less Secure Apps
Allow less secure apps: ON
然后我创建了一个应用程序密码并尝试了很多这样的配置:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-relay.gmail.com'
EMAIL_HOST_USER = 'noreply@mydomain.com'
EMAIL_HOST_PASSWORD = 'abcdefghiklmnopq'
DEFAULT_FROM_EMAIL = 'noreply@mydomain.com'
SERVER_EMAIL = 'noreply@mydomain.com'
EMAIL_PORT = 465
我找不到关于 Google 或 Django 如何配置设置的好文档。现在有人有好的资源吗? App Password/Less secure Apps 是正确的方法吗?因为 Google 有一些安全警告。 Noreply 是一个群组,但我为 my.name@mydomain.com 创建了应用程序密码。当我是小组的一员时,这是一个问题吗?我还尝试了几个选项 my.name@mydomain.com 而不是 noreply@mydomain.com 但我总是得到错误
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
在您的 settings.py
中使用它
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'noreply@mydomain.com'
EMAIL_HOST_PASSWORD = '#########'
EMAIL_PORT = 587
当用户在我的网站上注册时,会向用户发送一封电子邮件以确认 his/her 电子邮件。 它适用于此设置:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemail@gmail.com'
EMAIL_HOST_PASSWORD = 'abcdefghiklmnopq'
EMAIL_PORT = 587
现在我想切换到 noreply@mydomain.com。 我在 G Suite 上创建了一个帐户并进行了以下配置:
Comprehensive mail storage (Locally applied)
Ensure that a copy of all sent and received mail is stored in associated users' mailboxes: ONSMTP relay service (Locally applied)
ms_mail
Allowed senders: Only addresses in my domains
Only accept mail from the specified IP addresses: No
Require SMTP Authentication: Yes
Require TLS encryption: YesLess secure apps (Locally applied)
Allow Users to manage their access to less secure apps Less Secure AppsAllow less secure apps: ON
然后我创建了一个应用程序密码并尝试了很多这样的配置:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-relay.gmail.com'
EMAIL_HOST_USER = 'noreply@mydomain.com'
EMAIL_HOST_PASSWORD = 'abcdefghiklmnopq'
DEFAULT_FROM_EMAIL = 'noreply@mydomain.com'
SERVER_EMAIL = 'noreply@mydomain.com'
EMAIL_PORT = 465
我找不到关于 Google 或 Django 如何配置设置的好文档。现在有人有好的资源吗? App Password/Less secure Apps 是正确的方法吗?因为 Google 有一些安全警告。 Noreply 是一个群组,但我为 my.name@mydomain.com 创建了应用程序密码。当我是小组的一员时,这是一个问题吗?我还尝试了几个选项 my.name@mydomain.com 而不是 noreply@mydomain.com 但我总是得到错误
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
在您的 settings.py
中使用它EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'noreply@mydomain.com'
EMAIL_HOST_PASSWORD = '#########'
EMAIL_PORT = 587